How to install Docker and docker-compose

A roadmap to install Docker and docker-compose in Linux.

Dmitry L Rocha
The Miners
3 min readFeb 1, 2017

--

Docker is a tool to wrap a piece of software in a complete filesystem that contains everything needed to run an application, such as code, runtime, system tools, and system libraries. This guarantees that the software will always run in the same way, regardless of its environment.

docker-compose is a tool to aid in starting a plenty of software using Docker and configuring anything in a yml file. With this you don’t need to know by heart any large command line nor to create a script for that.

To Install

If you don’t use pacman to install software (or you don’t know what that means), run the following command to install Docker:

This script will run in Debian, Fedora, Oracle, CentOS, and RedHat (as well as any derived distro).

Now let’s go ahead and configure it.

Starting Docker

If you don’t know how the booting system works on your machine (or you don’t know what that means), it is likely that docker already starts as soon as your machine boots up, but if you need to manually start Docker, you can do it with this command:

And if you receive this error:

You are likely running a new version of Ubuntu and you have to run this:

Tip by Marina Limeira :)

Alright, let’s move on to the configuration.

Configuring Docker

Now you have to add your user to a group called docker.

There are a lot of ways to do this, here is a simple approach that works in any distribution:

1º. Edit /etc/group , this is a system file so you will have to prefix your command with sudo, like:

2º. Look for a line similar to:

There is no problem if the group number is different. Now add your username to the group:

In case your computer is used by more than one person, split the usernames using comma, i.e.:

Use control+x and enter to save the file.

Once more: there are a lot of ways to do this, but I will show you only one:

3º. Logout from your user account then login again.

To test, open your terminal and run:

If the return of this command is something like:

It means everything is ok :).

Checking the configuration

To test using Ruby REPL:

The first time you execute this command it shows you a progress bar, which is normal: Docker downloads the containers that you don’t have in your machine from docker hub.

Type exit and fire the command again: you will notice it won’t re-download the containers.

Now I will explain a little bit about the command above:

  1. docker is the software you run to connect to Docker daemon;
  2. run is a subcommand, it means to “run a software in a container and exit”;
  3. The -it means to run Docker in interactive mode and tty mode, i.e., to run a command and “attach” it to your terminal :P
  4. ruby is the name of the image in Docker Hub;
  5. irb is the command to run within the container. Try to execute the same command using bash instead.

To Install docker-compose

The installation of docker-compose is the one I see people making mistakes more often (including myself).

In Linux:

1º. Change to root:

2º. And execute this line:

And then:

This information is in Install Docker Compose — Docker.

Conclusion

Docker and docker-compose are tools I am using a lot lately. I have already uninstalled databases, Ruby and other development tools from my computer.

To test your installation and have a starting point adding them to your project, I recommend you to take a look in these two projects:

You only need to go through their README. Have fun!

--

--