Software development infrastructure. Part 0x01. Setting things up. Docker.

in #utopian-io6 years ago (edited)

In my first post I’ve presented rough plans for this series. Now time to set things up.

Introduction

This is the first part of a tutorial aimed at setting up a development infrastructure. Well, it's the second part, but the first with anything to do, and not only read.

About Docker

A toy whale
MY WHALE IS BETTER THAN YOUR WHALE Source: Pixabay

The first thing to install is docker. It is a containerization platform. The very general idea is to build around your software to create a container – like a separate server with separate resources and easily set up or torn down. And replaceable. But it’s not really a separate server, neither a virtual machine. Container does behave like a separate, independent machine, but it is run using a specially crafted platform that fakes it within your operating system. It’s done in a way that uses resources much more efficiently. I won’t be getting into more details as there are people much smarter than me who can present and explain such stuff. Remember, I am a boring software engineer. A sample resource on the subject

Docker logo
Source: Docker website

To run a Docker container, you need an image – this is kind of a pre-built definition of what can be loaded as a container. You can build your own images or use some of the preconfigured ones from the Docker Hub, like one for Jenkins, Gitlab, Nexus and so on.

The general idea for now is to set everything up using docker: compose the containers in a way that will make them work together. We can set each machine up on its own, using a command prompt startup parameters, but there are tools that enable composing the machines and make it easier for them to talk to each other. One of them is docker-compose. You can write a file that defines all services, their properties, even networking between them, then you provide it to docker-compose command and it starts it all up for you.

DockerComposeRule

Just a small comment here. While Docker and Docker compose are a very handy way to set up your company's infrastructure, this isn't the only application of its functions.

We use docker-compose for system testing at work. There is a tool called docker-compose-rule which provides a Junit rule. You provide a reference to the mentioned document in it, then when setting up the tests, it starts all the containers in the file, next you can run the tests, then it cleans up. The nice addition is that is can execute the services remotely on your dedicated docker host, and even send over the locally built images. Because we needed to set up different conditions for different test cases, we have created a docker-compose file generator that matches our products setup and we can simulate many situations like bad network conditions, bridging over several networks etc. Handy.

Installation

Back to setting things up. For now we have to things to do: install Docker and install Docker-compose.

Before we continue, if you don’t like reading documentation, I strongly recommend you start liking it. Really. It is not only a useful source of information, it is also a perfect alibi to moan around at low quality of resources and an excellent way to get through an eight hour day of work. It’s also a good place to start your adventure with open source projects (improve current docs, add new ones).

Snaps

If you want, you can try using snaps to install docker and docker-compose. It might work very well, but then I don’t know it and may not be able to help you. I like following vendors’ instructions, so I did the below once, and tried snap once. It worked. Note: snaps are a different form of containers.

brzeczyszczykiewicz@machine:~$ sudo snap install docker 
[sudo] password for brzeczyszczykiewicz: 
2018-01-07T20:48:30Z INFO Waiting for restart...
docker 17.06.2-ce from 'docker-inc' installed
brzeczyszczykiewicz@machine:~$ sudo addgroup --system docker
[sudo] password for brzeczyszczykiewicz: 
Adding group `docker' (GID 130) ...
Done.
brzeczyszczykiewicz@machine:~$ sudo adduser $USER docker
Adding user `brzeczyszczykiewicz' to group `docker' ...
Adding user brzeczyszczykiewicz to group docker
Done.
brzeczyszczykiewicz@machine:~$ newgrp docker
brzeczyszczykiewicz@machine:~$ sudo snap disable docker
docker disabled
brzeczyszczykiewicz@machine:~$ sudo snap enable docker
docker enabled

And that’s all. I may need to withdraw from it as I have a very limited SSD space on my computer and don’t really know how to change the location of whatever Docker downloads (or where it’s stored to begin with).
Just a trick for the future: my computer died while running docker and it would not work after the restart. I ran journalctl _SYSTEMD_UNIT=snap.docker.dockerd.service to get the errors, fixed them and then systemctl start snap.docker.dockerd.service got it back up. In my case there was a leftover pid file that gets removed when the daemon shuts down gracefully

For the install below it may not be trivial, but it is doable without great effort.

Using Docker package repositories

For non-snappers and vendor docs fans:
Docker provides a tutorial if you want to learn more. If not, just install it, next configure a couple more things - I am mainly thinking about enabling usage of docker as a non-root user. It’s handy and safer, I think. I don’t know if docker gets started on boot by default, but if you aren’t using it regularly, I would suggest you make sure it does not.
Next install docker-compose using the instructions or using the setup for docker and running

sudo apt-get install docker-compose

I don’t know why the instructions don’t mention this. I have created a pull request to add this info. When I clicked the page edit link in Docker documentation, GitHub forked the repository and let me edit the page markdown. Next it automatically created a branch with my change and helped me create a pull request to have the changes merged. And it all happens in a browser. Nice experience.
UPDATE: The pull request has been rejected as the repositories should not be relied on when it comes to docker-compose. I have passed the info on to ops in my company as they planned to use it in the future.

Testing the installation

You should have your docker up and running. To test it all, run the following command:

docker run hello-world

If it worked, well done. If not, well done, now go troubleshoot.

What happens in this command? It downloads a hello-world image from Docker Hub and executes it.

Other useful commands

Apart from docker run Docker has many useful commands, I will be mentioning them in next parts as they are needed, but just to let you get some insight, remember

docker help

It lists all commands available. Then you can run for instance

docker help ps

... which will describe how to list the running and non-running containers.

I do encourage you to have some fun with it.

Summary

That’s it for today. If you’d like to do something extra, try having fun with what you’ve installed. You can for instance use WPScan to check how secure and up to date your favourite blogs are (and let their owners know that they can do better). You can write a docker-compose file for hello-world.

Remember: THE DUMBEST QUESTIONS ARE THOSE NEVER ASKED

I have set up a git repository to host whatever files I may need in this tutorial. The readme also contains links to articles. The first code referes to part 0x02 and I hope to be able to release this soon. Till then, here's a spoiler alert: you might lose some of the surprise.

Homework

I have a competition for you. Find the most peculiar docker image in Docker Hub. Provide a justification to your selection and I will choose the one I like most. Frankly, I looked for some and the only I had found was a DOSBox container that you can attach to your X session. The winner will receive 1 SBD from me, and I will select the winner after this article’s payout. Even if it is the only entry. It cannot be DOSBox, Hello-world nor WPScan container.

Series



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

i am robot think that very cool i up vote

Happy to see another baker + developer ;) Upvote!

#codebakers ? ;)
I don't know why I haven't previously followed you, I remember I intended to do it. Fixing now.

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Thanks! Have a good weekend :)

Hey @breadcentric I am @utopian-io. I have just upvoted you!

Achievements

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • This is your first accepted contribution here in Utopian. Welcome!

Suggestions

  • Contribute more often to get higher and higher rewards. I wish to see you often!
  • Work on your followers to increase the votes/rewards. I follow what humans do and my vote is mainly based on that. Good luck!

Get Noticed!

  • Did you know project owners can manually vote with their own voting power or by voting power delegated to their projects? Ask the project owner to review your contributions!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.033
BTC 64222.08
ETH 3135.29
USDT 1.00
SBD 3.99