Install Docker On Ubuntu 18.04 Bionic Beaver
Aim
Install Docker production ready on Ubuntu 18.04 LTS Bionic Beaver AWS EC2 instance
Requirements
AWS EC2 Account
Level
Easy
Introduction
AWS and Docker have revolutionised how web applications are hosted and managed in the cloud and how they are developed and deployed to customers.
Docker allows developers to containerise their applications with the power of virtual machines, but without the weight, they are easier to deploy and move from dev, staging, qa and production having a consistent environment across all platforms and stages.
Installing Docker on Ubuntu hosted by AWS is simple.
Install Docker
First you need to ssh onto the EC2 instance, then run the following commands to update the package manager and install docker
sudo apt-get update
sudo apt-get install docker.io
Start the docker daemon and enable the service to start on boot
sudo systemctl start docker
sudo systemctl enable docker
It’s recommended to add the current user to the docker group. This will prevent you running into permissions issues when running docker commands or having to run the commands as sudo
sudo usermod -a -G docker $USER
Running a container
docker run -d -p 80:80 dockerup/quicksite
This will start an engine server with a single landing page.
Make sure port 80 is open on your firewall by checking the security group assigned to your EC2 instance, you can then load the site by browsing to http://<EC2PublicIpAddress>
Working with Containers
Working with containers is pretty straightforward. The aboverun
command along with the -d
flag detaches the container, so it’s not taking up your terminal and starts the internal process in this case nginx and binds the container to port 80
Since you can have multiple containers either running at the same time or terminated, its good to be able to keep track of them all. To list out all the running containers on your system, use the ps
option. Use the -a flag to see all containers either stopped or running
docker ps -a
If you want to stop a container, use stop
followed by the hash or name of the container.
docker stop <CONTAINER NAME OR HASH>
Removing a container is easy too. Use rm
.
docker rm <CONTAINER NAME OR HASH>
If you would like to stop and remove all containers you can combine commands
docker stop $(docker ps -aq) && docker rm $(docker ps -aq)
Summary
Combining Docker and a cloud provider like AWS is very powerful. AWS and the Docker ecosystem provide far more options to managing container environments shown here, and Docker is capable of a wide range of different configurations. With the details here, you can at least get started with Docker, AWS and Ubuntu and use it to configure a production ready Docker server for launching your apps