Abstract:

What Docker is, in short, is a new generation of lighter, better virtual machine technology. Here are the installation steps:

First, MAC/Windows platform installation

Docker is developed on the basis of the Linux kernel, can not run directly on MAC/Windows, need to use the docker-machine tool, first build a Linux virtual machine on MAC/Windows, and then continue to play. The default built-in virtual machine engine is Oracle’s free VirtualBox, which supports commercial software such as vmware Fusion.

1.1 Download docker Toolbox

Download: www.docker.com/docker-tool… , Toolbox has been integrated with plug-ins of Docker-Machine, Docker Client and Virtualbox. It is strongly recommended that students learning Docker on MAC/Windows install Docker in this way (Note: Brew Install is also available on MAC, but it is not easy to learn without a graphical interface).

The installation process is simple, all the way to Next, and the only thing to notice is the final interface:

Docker Toolbox provides two modes of operation: terminal command line and graphical interface. Beginners are advised to choose graphical interface to reduce learning difficulty.

After entering, it will be required to create a Docker Hub account first, register the account to complete mailbox verification, you can enter, Docker Hub provides a large number of Docker image files (can understand the template of various virtual machines, but it is recommended to turn ~* wall, otherwise the speed is extremely slow, or even can not open), basically can meet various requirements, For example: if you need a continuous integration VIRTUAL machine, you can use Jenkins image directly, if you need a mysql, you can use mysql image directly…

Chinese programmers are probably the happiest programmers in the world, all the good foreign stuff either doesn’t work or is slow, docker Hub download is very slow, wait for your first contact, we will introduce how to use the domestic daoCloud agent to speed up.

Note: Toolbox does not provide an uninstall tool. If you need to uninstall it for some reason, you can use github.com/docker/tool… The script is complete and reads as follows:

#! /bin/bash
# Uninstall Script

if [ "${USER}"! ="root" ]; then
	echo "$0 must be run as root!"
	exit 2
fi

while true; do
  read -p "Remove all Docker Machine VMs? (Y/N): " yn
  case $yn in
    [Yy]* ) docker-machine rm -f $(docker-machine ls -q); break;;
    [Nn]* ) break;; *)echo "Please answer yes or no."; exit 1;;
  esac
done

echo "Removing Applications..."
rm -rf /Applications/Docker

echo "Removing docker binaries..."
rm -f /usr/local/bin/docker
rm -f /usr/local/bin/docker-machine
rm -r /usr/local/bin/docker-machine-driver*
rm -f /usr/local/bin/docker-compose

echo "Removing boot2docker.iso"
rm -rf /usr/local/share/boot2docker

echo "All Done!"
Copy the code

The script above does not remove VirtualBox. If you want to uninstall VirtualBox, go to the Application panel and drag virtualBox into the trash.

1.2 Downloading an Image

Use a smaller mirror to test nginx, such as kitematic/hello-world-nginx

Click New, search nginx will find, the document address is: hub.docker.com/r/kitematic… The download process through the GUI interface is equivalent to the following command:

docker pull kitematic/hello-world-nginx
Copy the code

1.3 Some general operations

Below is the KI GUI interface. The red circle can be directly operated. Click “Start” in the toolbar to Start the Nginx container

Click the “Browse nginx home page” button in the image above, and you can see the nginx home page directly in your browser. The STOP/RESTART buttons on the toolbar are known by their names.

Can have students noticed that the address in the browser like: http://192.168.99.100:32774, if you want to know is what is the IP and port, we can see next page Ports, the diagram below:

Port 80 of docker container is mapped to port 32774 of vm. Where is 192.168.99.100?

Click the DOCKER CLI in the lower left corner to enter the DOCKER terminal, and then run:

docker-machine lsCopy the code

The current virtual machine is displayed, the default output is the name of the virtual machine, and then run:

docker-machine ip default
Copy the code

The IP address assigned by the virtual box to the default vm. To continue, click Exec in the image below to enter the bash command line mode of the nginx Docker container:

Enter nginx -v to view the location of the configuration file:

/etc/nginx/nginx.conf /etc/nginx/nginx.conf

From the image above, the site’s root directory is /website_files. Go back to KI and click on the Volumns TAB

Can see is actually a ~ on the MAC native/Documents/Kitematic/hello – world – nginx/website_files mapped to the docker containers in the instance/website_files, You can try a MAC native ~ / Documents/Kitematic/hello – world – the index of nginx/website_files. HTML changes, nginx to refresh the browser page, should immediately see the effect.

1.4 Docker command Line secrets

If you open a terminal directly on your MAC and type a command like docker ps, it will prompt you

Cannot connect to the Docker daemon. Is the docker daemon running on this host?
Copy the code

However, after clicking DOCKER CLI to enter the terminal from KI interface and then entering DOCKER PS, the running container information can be normally displayed:

The reason is as follows: After entering the terminal through KI, the execution is performed first

bash -c "The clear && DOCKER_HOST = TCP: / / 192.168.99.100:2376 DOCKER_CERT_PATH = / Users/yjmyzz /. Docker/machine/those/default DOCKER_TLS_VERIFY=1 /bin/zsh"
Copy the code

In the DOCker CLI terminal, you can find this secret by clicking the up arrow. Wrap up this long command line.

bash -c "The clear && DOCKER_HOST = TCP: / / 192.168.99.100:2376 DOCKER_CERT_PATH = / Users/yjmyzz /. Docker/machine/those/default DOCKER_TLS_VERIFY=1 /bin/zsh"
Copy the code

There is nothing special about it, just a few bash variables are defined. This paragraph can be simplified as:

docker-machine start default If the VM is not started, execute this line first
docker-machine env default Get the environment variable of default
Copy the code

When the second line completes, it prints:

export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="TCP: / / 192.168.99.100:2376"
export DOCKER_CERT_PATH="/Users/yjmyzz/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell:
# eval $(docker-machine env default)Copy the code

Docker-machine env default (env default, docker-machine env default);

Similarly, clicking EXEC on the top toolbar is effectively equivalent to

bash -c "The clear && DOCKER_HOST = TCP: / / 192.168.99.100:2376 DOCKER_CERT_PATH = / Users/yjmyzz /. Docker/machine/those/default DOCKER_TLS_VERIFY=1 docker exec -it hello-world-nginx sh"
Copy the code

Wrap it up:

bash -c "The clear && DOCKER_HOST = TCP: / / 192.168.99.100:2376 DOCKER_CERT_PATH = / Users/yjmyzz /. Docker/machine/those/default DOCKER_TLS_VERIFY=1 docker exec -it hello-world-nginx sh"
Copy the code

Only the last line is added, so the paragraph above is equivalent to:

eval $(docker-machine env default)
docker exec -it hello-world-nginx sh
Copy the code

2. Installation on Linux (using centos as an example)

Note: centos requires a higher version than 7. Earlier versions of the kernel do not support docker.

curl -sSL https://get.daocloud.io/docker | sh 
sudo chkconfig docker on 
sudo systemctl start docker
Copy the code

Have to 3 lines of code, the line 1, from domestic daocloud download, if you want to download from the website, can change to sudo yum install docker or curl – sSL https://get.docker.com/ | sh, after the installation is complete, Perform:

sudo systemctl status docker
Copy the code

Check the Docker deamon status. If active(running) is displayed, the Docker is running properly.

Reference article:

Docs.docker.com/engine/inst…

The original link