|Docker is an open-source project that automates the deployment of applications inside software containers, by providing an additional layer of abstraction and automation of operating-system-level virtualization on Linux. Docker uses resource isolation features of the Linux kernel such as cgroups and kernel namespaces to allow independent "containers" to run within a single Linux instance, avoiding the overhead of starting virtual machines.
The latest Docker version can be downloaded from: http://www.docker.com
Operating system used
Windows Vista Home Premium SP 2
Docker on Windows
- Install and run a CentOS container, type: docker run -it centos /bin/bash
- i = interactive, t=assign pseudo-tty (aka terminal)
- centos is the image the container will be based on. The container will be running a CentOS.
- Run the application/process. In this example: /bin/bash in CentOS
- A copy of the centos image was not found locally, so it is downloaded (=pulled) from Docker hub (the public Docker registry). For example: https://registry-1.docker.io/v1/
You can search the Docker Hub, see:
- The CentOS base image is comprised of 3 layers: fd429..., 6941bf..., 41459f...
These 3 layers needs to be downloaded.
- Docker hub contains many different centos versions, each with its own tag. If you do not specify a tag in the run command docker run -it centos:<tag>, Docker will pull the centos image tagged with "latest".
- If you use the run command and do not specify a name, a random name is automatically assigned.
This random name can be found when using the command docker ps -a
To assign a name, type: docker run -it --name mycentos centos /bin/bash
- A super lightweight barebone CentOS is installed. You can type Unix commands, for example:
- Ping Google DNS: ping 188.8.131.52
- Show running processes: ps -elf
- Install vim: yum install -y nano
- Show the content of the hosts file, type: cat /etc/hosts
The hostname "1900fc506c34" is the hosts file matches the PS1 prompt "[email protected]" which is also our container id.
- Create a test file, type: nano /tmp/test.txt and enter the text: Hello World
- Stop the container, type: exit
- Check if no containers are running, type: docker ps -a
Our container id "1900fc506c34" is not running.
- Switch to root user, type: sudo su
- Go to the folder /var/lib/docker/aufs/diff/ where all containers are located.
Type: cd /var/lib/docker/aufs/diff/
- Show the content of this folder, type: ls -al
The hostname "1900fc506c34" is the hosts file matches the PS1 prompt "[email protected]".
- Go to the folder starting with "1900fc506c34".
Type: cd 1900fc506c34...
And show its content, type: ls -al
- The tmp folder will contain the test.txt file created earlier.
- To start this particular container, type: docker start 1900fc506c34
And attach to this container, type: docker attach 1900fc506c34
- You can still access the /tmp/test.txt file, type: cat /tmp/test.txt
- To exit a running container without killing it, press the keys: CTRL+P followed by CTRL+Q
After pressing these buttons you will return to your Docker host.
Pressing the keys CTRL+C in a running container, is the same as you type: exit.
Both methods will stop the container.
To attach to a running Docker process, type: docker attach <image id>
Press the Enter key to get the promp back.