Install Docker on Ubuntu
Docker is an open-source software for “application distribution”. At first this sounds quite abstract. At least that’s what I thought some time ago and until I started to deal more with Docker. Today I would like to bring Docker closer to you in this first Docker-article and support you along the way. This blog entry is intended for users who want to make their first steps with Docker. There are further contributions, which go a bit deeper. More on that later on.
If you have any suggestions for improvement on this article, feel free to reach out to email@example.com. We love engaged readers :).
Before we get started, three important terms:
- Image: A completed docker container that you can easily port or duplicate from one host to the next host.
- Container: A virtual operating system ready to receive a docker application.
- Dockerfile: A collection of commands and parameters to adapt an existing image to your own needs. For example, changing passwords, configuring domains, etc.
I based this article on an Ubuntu 16.04 LTS installation, but of course you can use other distributions.
Preparing the server
Click on somewhere an Ubuntu 16.06 LTS together. If you have no platform for it, just take gridscale. You can enter the coupon code “docker16” after login and activation of your account, then you have a small credit with which you can follow this tutorial yourself. Please do not forget to delete all resources after your test so you do not incur any costs.
Then log on to your Ubuntu server via SSH and first install the package ‘curl’:
$ apt-get install curl
I use ‘curl’ to run a Docker script, that will install Docker for me (laziness – of course, you can manually install all packages).
So, this is the way for lazy people 🙂 :
$ curl https://get.docker.com | bash
Now the script is downloaded, which supplements a few package lists, updates them on your server with ‘apt-get update’ and then installs docker as well as a few other packages. After the script is finished, you can:
$ systemctl status docker
Check whether the docker is ready for use. My output looks as follows:
docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since So 2016-06-19 15:48:30 CEST; 17min ago Docs: https://docs.docker.com Main PID: 912 (docker) Tasks: 18 Memory: 50.5M CPU: 533ms CGroup: /system.slice/docker.service ├─912 /usr/bin/docker daemon -H fd:// └─931 docker-containerd -l /var/run/docker/libcontainerd/docker-containerd.sock --runtime docker-run
Important Docker commands
Now that you’ve successfully installed Docker, it’s all about how to use Docker. There is one central command: ‘docker‘
If you call on Docker without parameters, you get a longer list of parameters that Docker accepts. The structure is always identical:
docker [option] [command] [argument]
If you want to get more help for a single option, you can call on the Docker command as follows
docker [option] –help
Now to the first command. Look at the status of your Docker system with:
$ docker info
You will get a few statistics and you can read the status of your Docker system.
Installing a Docker Image
Now just try to install your first Docker image. By default, Docker is using a kind of central marketplace for docker images called the “Docker Hub”. This Docker Hub is operated by Docker itself and is available to everyone to publish their own Docker images. Meanwhile, a large community has formed around the Docker Hub. It is definitely worth while to take a look. I would bookmark it directly: https://hub.docker.com
One of the simplest Docker images is “hello world”. Install this image to get a feel for the sequences.
$ docker run hello-world
The output should be similar to the following:
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world a9d36faac0fe: Pull complete Digest: sha256:e52be8ffeeb1f374f440893189cd32f44cb166650e7ab185fa7735b7dc48d619 Status: Downloaded newer image for hello-world:latest Hello from Docker. This message shows that your installation appears to be working correctly. …
If you call ‘dockerinfo’ again, you will see a difference to before: You have installed your first docker container.
But if that is all it would be a little boring. You can use the following command to perform a search on the Docker Hub to install additional containers if necessary.
$ docker search [search term]
Search for ‘wordpress’, for instance – but wait with the installation – we will run through it together right now.
Installing MySQL with Docker
You need a database first in order to install WordPress. There are also Docker images for databases and the like. Sometimes, however, these Docker images require a more advanced configuration or other parameters. In general, the description of the Docker images is of great use. Here you can find the description for MySQL, for instance.
Now to the installation:
$ docker run --name my-mysql -e MYSQL_ROOT_PASSWORD=mypassword -d mysql
The command now does the following:
- First, it checks whether mysql already exists locally. If not, Docker tries to download the image from the hub.
- Then an instance is created that has the name “my-mysql”.
- The installation script is supplied with an environment variable (MYSQL_ROOT_PASSWORD = my password)
- -d stands for detach – the process continues in the background
- mysql is the name of the docker image
After the command from above, you can verify that your MySQL instance has started successfully.
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1628664378aa mysql "docker-entrypoint.sh" 3 minutes ago Up 3 minutes 3306/tcp my-mysql
Installing WordPress with Docker
Well, you already have some practice. Continue with the installation of WordPress. The corresponding parameters are similar to MySQL in the description of the Docker image of WordPress.
For the installation you can use the following for example:
$ docker run --name my-wordpress --link my-mysql:mysql -p :8080:80 -e WORDPRESS_DB_USER=root -e WORDPRESS_DB_PASSWORD=mypassword -d wordpress
Probably you just noticed that I work everywhere with the user ‘root’. This is, of course, not recommended for productive environments. I will deal with the legal structure and eligibility concepts in a separate article.
In the above command line there is a special feature that you have to adjust.
‘-p <your public IP>:8080:80’
Simply use the public IP address of your system. See what docker images are running on your server:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7799bbeb6543 wordpress "/entrypoint.sh apach" About a minute ago Up About a minute <your public IP>:8080->80/tcp my-wordpress 522d5cde1779 mysql "docker-entrypoint.sh" 5 minutes ago Up 5 minutes 3306/tcp my-mysql
That’s it! You can now reach your new WordPress via the public IP. Do not forget that the port is configured to 8080 🙂
In this article, I briefly described the installation of Docker as well as the example installation of a MySQL server plus a WordPress instance.
Docker is of course much more powerful and can be and do a lot more. I will dive deeper in later articles, especially looking at authorization concepts, creating your own Docker images, committing changes, and uploading stuff to the Docker Hub.
If you are missing something in this article, as always: Just let us know! 🙂 –> firstname.lastname@example.org.Zurück zur Tutorial Übersicht Back to Tutorial Overview
About Docker Docker is an open-source software for “application distribution”. At first this sounds quite abstract. At least that’s what I thought some time ago and until I started to deal more with Docker. Today I would like to bring Docker closer to you in this first Docker-article and support you along the way. This blog entry is […]
Thank you for your feedback!
We will get back to you as soon as the article is finished.