How to install and use Docker (32bits/X86 included)
Docker allows you to create disk images that you can share with others. Using tools like SaltStack, Chef or Puppet you can create and automate your image distribution model for server.
This tool allows you to have a similar environment as you have on your server that you can use in you laptop for example.
You can also use Docker’s central repository of disk images that allows you to create and run different OS (Ubuntu, Centos, Fedora ..etc)
It can be used as a version control system for your application’s OS
In general, Docker helps you work with a unique image of an OS/app through dev/test/qa/prod environments, which is great for creating a continuous integration/delivery process.
Write once, run everywhere!
Let’s see how it works.
Please note that Docker is only supported on amd64 platforms. In this case, please follow this tutorial.
If you had any problems/bugs, you can also try to use this script.
The next installation procedure concerns 64bit CPUs and we are going to try Docker using an Ubunut/Debian system.
If you installed Docker on your 32bit machine, skip the installation part.
Note that if you are using Trusty 14.04 you will not have any requirements.
Some Ubuntu OS versions require a kernel version higher than 3.10 to run Docker, see the prerequisites on this page that apply to your Ubuntu version.
Check your kernel :
for me it is :
And I upgraded my Linux Mint and I am using Ubuntu trusty repositories for the next steps.
Please refer to this page, for more details.
Start by upgrading your system:
sudo aptitude update sudo aptitude -y upgrade
sudo apt-get install linux-image-extra-`uname -r` linux-image-generic-lts-trusty
And reboot your host.
Good, we are able to install Docker:
wget -qO- https://get.docker.com/ | sh
You can also use the repository:
sudo sh -c "wget -qO- https://get.docker.io/gpg | apt-key add -" sudo sh -c "echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list" sudo apt-get update sudo aptitude install lxc-docker
If you have finished the installation (for both 32 and 64bits), try to verify if everything is fine, check the version of Docker:
sudo docker version
You will be able to see something like the similar output:
Client version: 1.0.1 Client API version: 1.12 Go version (client): go1.2.1 Git commit (client): 990021a Server version: 1.0.1 Server API version: 1.12 Go version (server): go1.2.1 Git commit (server): 990021a
If you want Docker help, enter:
You will see a list of commands and their description:
Commands: attach Attach to a running container build Build an image from a Dockerfile commit Create a new image from a container's changes cp Copy files/folders from the containers filesystem to the host path diff Inspect changes on a container's filesystem events Get real time events from the server export Stream the contents of a container as a tar archive history Show the history of an image images List images import Create a new filesystem image from the contents of a tarball info Display system-wide information inspect Return low-level information on a container kill Kill a running container load Load an image from a tar archive login Register or Login to the docker registry server logs Fetch the logs of a container port Lookup the public-facing port which is NAT-ed to PRIVATE_PORT pause Pause all processes within a container ps List containers pull Pull an image or a repository from the docker registry server push Push an image or a repository to the docker registry server restart Restart a running container rm Remove one or more containers rmi Remove one or more images run Run a command in a new container save Save an image to a tar archive search Search for an image in the docker index start Start a stopped container stop Stop a running container tag Tag an image into a repository top Lookup the running processes of a container unpause Unpause a paused container version Show the docker version information wait Block until a container stops, then print its exit code
Docker: Hello World!
sudo docker run hello-world
This will pull the repository “hello-world”. You have now a container for testing purposes.
Optional configurations on Ubuntu:
According to the official documentation of Docker:
The docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can access it with sudo. For this reason, docker daemon always runs as the root user.
So Docker suggests the following:
To avoid having to use sudo when you use the docker command, create a Unix group called docker and add users to it. When the docker daemon starts, it makes the ownership of the Unix socket read/writable by the docker group.
But please take a look at the security impacts of what we are going to do right now.
Follow now the steps in this page.
This will let you :
- Create a docker group
- Adjust memory and swap accounting
- Enable UFW forwarding
- And configure a DNS server for use by Docker
Searching for an image
Let’s suppose you are looking for an Ubuntu image.
sudo docker search ubuntu
You will have this output from the images repository as a response to your query:
In order to download or pull the official Ubuntu image (see the first element in the list):
sudo docker pull ubuntu
Wait for the download and the install, it could take time.
After that, you will be able to see your image, and the list of all local images (you will find “hello-world” image already listed if you followed this tutorial from its beginning ):
sudo docker images
Every listed image has its own “IMAGE ID”. Note that we are going to use this id to commit any changes to the Docker image:
Committing a change to a Docker image
Like Git, you can have some changes that you’ve done in you local image, you can then push it to the images repository and have your own “fork”.
sudo docker commit [id] [name of the image]
sudo docker commit 9b487409b08f my_new_image
Create an account at: hub.docker.com/account/signup
and push the changes:
sudo docker push my_username/my_new_image
Type then your password.
This is very similar to Git or when using Github.
Well, it was the first tutorial, next ones will cover more important subjects and more advanced topics.
Happy hacking !