If you're itching to get Docker up and running, don't let the installation process scare you. See how quick and easy it is to install Docker with the help of Ubuntu 16.04.
You've heard of Docker, and you know that it's one of the best means of packaging your application into a standardized unit for deployment—you want that...but you're not sure how to get it up and running.
To the uninitiated, Docker looks to be a complicated mess of an install. If you're unsure where to start, the installation can be daunting. Truth be told, the installation is quite simple. I'll help demystify that very process, so you can have Docker installed and ready to serve.
I'll demonstrate this process on a fresh installation of Ubuntu 16.04. The entire installation process is handled via command line, so prepare to type.
Update apt and add the key and repo
The first thing to do is update apt. To do this, open a terminal window and issue the command sudo apt-get update. Once that finishes, a new GPG key must be added for the repository used to install Docker. To add the new key, issue the following command:
sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
The next step is to add the Docker repository. From the terminal window, create the new file with the command sudo nano /etc/apt/sources.list.d/docker.list and add the following contents:
deb https://apt.dockerproject.org/repo ubuntu-xenial main
Save and close that file. Once again, update apt with the command sudo apt-get update.
Install the dependencies
Before we install Docker, there are a couple of dependencies that must be taken care of—these can all be handled with a single command. Go back to your terminal window and issue the following:
sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual
You're ready to install Docker.
Installing, starting, and testing Docker
Docker can now be installed with a single command. From the terminal, issue the following:
sudo apt-get install docker-engine
When the installation completes, you'll want to add your user to the Docker group with the command:
sudo usermod -aG docker $USER
Once your user has been added, you can run the docker command as your standard user.
In order to run a Docker command, you must first fire up Docker with the command sudo service docker start. You can now test to make sure Docker is installed and running properly by downloading the hello-world test image. From the terminal window, issue the command docker run hello-world. The hello-world image will download and run (Figure A).
The Docker hello-world image in action.
Docker is ready to serve
Congratulations! You now have a working Docker installation...ready to deploy your applications. You can head over to the Docker Hub and find other applications to run. Some of these applications will require you to create a docker-compose.yaml file. Say, for instance, you want to install WordPress with Docker. To do this, create the folder my-wordpress. Change into that directory and create the docker-compose.yaml file with the following contents (do not use tabs for indentation, as that will cause Docker to error out).
version: '2' services: db: image: mysql:5.7 volumes: - "./.data/db:/var/lib/mysql" restart: always environment: MYSQL_ROOT_PASSWORD: wordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress wordpress: depends_on: - db image: wordpress:latest links: - db ports: - "8000:80" restart: always environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_PASSWORD: wordpress
Save that file and then, from within the my-wordpress directory, issue the command docker-compose up -d and WordPress will build. Once the build is complete, point your browser to http://IP_OF_SERVER:8000 (IP_OF_SERVER is the actual IP address of the machine running the Docker-installed instance of WordPress) and walk through the WordPress setup.
You've officially installed your first application from Docker.
You can go through the Docker Hub and check out the listed apps. Each installation will be different (some can be pulled directly from the Hub, without a .yaml file), but Docker makes installing these applications incredibly simple. And once you have your own software ready, you can deploy it through Docker as well.
- Docker rocker: container technology usage doubles; serious money follows (ZDNet)
- Raspberry Pi and Docker: Tiny $35 computer gets major new release of HypriotOS (ZDNet)
- How to spin up OrangeHRM as a virtual machine in less than 5 minutes (TechRepublic)
- How to run VirtualBox virtual machines from the command line (TechRepublic)
- How to install openDCIM on Ubuntu to simplify data center management (TechRepublic)
- How to install a LAMP server on openSUSE (TechRepublic)
- Digital transformation, the Red Hat way (Tech Pro Research)