docker initial, what is the docker

docker entry

1. docker acquaintance

1.1 Why docker?

1.2. Advantages docker container

More efficient use of system resources 
faster start-up time
consistent runtime environment of
continuous delivery and deployment
easier migration

 

2 docker three concepts

Three basic concepts container 
mirror image
container container
warehouse Repository
Docker is the entire life cycle of these three concepts.

 

3. docker installation

There are two installation methods

The first official 3.1 installed (version relatively new, but may be slower)

The official tutorial below, most correctly installed docker posture, if you want to install the official version on the use of this method

1. Uninstall the old version of 
sudo yum the Remove Docker Docker Docker-Client-Client-Latest-the Common Docker Docker Docker-Latest-Latest-logrotate logrotate-Docker Docker-SELinux SELinux-Docker Docker-Engine-Engine 2. Set the repository sudo yum -Y-utils Device yum the install-Mapper Data-persistent-LVM2 the sudo yum-config-Manager---add the repo https://download.docker.com/linux/centos/docker-ce.repo 3. installation docker community Edition sudo yum -y install Docker-ce 4. start close Docker systemctl start Docker










3.2 second use Ali cloud sources, download and install fast, but not the latest version

3.2.1 confirmation Ali cloud yum source file
vim /etc/yum.repos.d/Centos-7.repo
3.2.2 Using yum start the installation docker
yum install -y docker
View docker version 3.2.3 installed
rpm -qi docker (not used)

 

4. docker using command

4.1.1 search online docker mirror
docker search hello-world
4.1.2 Download docker Mirror
docker pull hello-world
4.1.3 docker View Mirror

docker official update a lot of command, do not panic, the effect of these two commands are the same, which is all right with

docker images
docker image ls
4.1.4 Run docker Mirror
docker run fce(imageID)
4.1.5 View docker container running
docker container ls
4.1.6 View has been run container
docker ps -a

Note: If the docker container which does not have any background programs running, the vessel will exit, hang up

Note: If the docker container which does not have any background programs running, the vessel will exit, hang up

Note: If the docker container which does not have any background programs running, the vessel will exit, hang up

4.1.7 Configuration docker mirror Accelerator
https://www.daocloud.io/mirror#accelerator-doc # a command acceleration curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http: //f1361db2.m. daocloud.io # this command is actually changed docker in a configuration file which is registered mirrored address, you can look at the cat /etc/docker/daemon.json





Note: Here will encounter a pit, above the accelerator command will modify our /etc/docker/daemon.json file, which is a dictionary that there are grammatical errors, leading docker can not be started (reason is because one more comma)

Note: Here will encounter a pit, above the accelerator command will modify our /etc/docker/daemon.json file, which is a dictionary that there are grammatical errors, leading docker can not be started (reason is because one more comma)

Note: Here will encounter a pit, above the accelerator command will modify our /etc/docker/daemon.json file, which is a dictionary that there are grammatical errors, leading docker can not be started (reason is because one more comma)

4.1.8 container is running the application, you must first have an operating system based on

A task to run in the background

docker run -d centos / bin / sh -c "while true; do echo magic love drops going round in circles; sleep 1; done"
4.1.9 Log Information uninterrupted print container
Container ID docker logs -f
4.1.10 command into the container (containers have their own miniature operating system. Mini linux)
docker exec -it e80 /bin/bash
4.1.11 interactive run a container and into the container (that is, open and enter a new container)
docker run -it centos /bin/bash

If you do not centos this image, then it will be automatically downloaded from the Internet and run

4.1.12 delete docker Mirror
Mirror ID docker rmi

Note: You may not be able to successfully deleted, it will prompt the mirror image has a dependency, you need to remove the dependency mirror, and then delete this image

4.1.13 Submit to create a custom image (docker container commit)
1. We enter interactive centos container, found no vim command 
  Docker RUN -it centos / bin / bash
2. In the current container, install a vim
  yum install -y vim
3. After installing vim, exit to exit the container
  exit 4. See just installed vim container recording   Docker container LS -a 5. the submission of the container, creating a new Image   Docker the commit 059fdea031ba Tiger / CentOS-vim 6. the image file to view [the root @ Master / Home] Images Docker the REPOSITORY the TAG SIZE ID CREATED the IMAGE Tiger / Latest fd2685ae25fe CentOS-Vim. 5 minutes ago Member 348MB








4.1.14 Exporting image
docker save centos > /opt/centos.tar.gz
4.1.15 introduced mirror
docker rmi container ID 
Docker Images See
docker load </opt/centos.tar.gz
4.1.16 start container
docker start container ID
4.1.17 stop the container
docker stop container ID
4.1.18 and start new container

1 and outputs a new container hehe

docker run centos / bin / echo "hehe" # This is executed directly with local / bin / echo'hehe '

2 new container and customize a name qishi

docker run --name qishi -it centos / bin / bash # start a bash terminal, allow user interaction.
4.1.19 running a container ubuntu
docker run -it ubuntu /bin/bash

See all 4.1.20 container ID and image ID docker
# See all docker container record ID 
docker PS -aq # View all docker image ID docker ImagesRF Royalty Free -aq # delete all the docker container has been run record docker docker RM `PS -aq` # delete all docker mirror docker rmi `docker images -aq` NOTE: this is not a single quotation marks, is left is a lower case symbol (reverse single quotes)









4.1.21 Check the specified container port mapping
docker port 74a ?

View the process in the container

docker top 74a
4.1.22 external access to the container

1 app.py a program running in the container, runs at port 5000

-P 2 using random mapping parameters to a port on the virtual machine

Training RUN -d -P Docker / Python app.py the webapp -P parameter is a random mapping into the open port of the container port of the network

If this is not a local mirroring, docker run automatically download mirrors for us

3 using a custom parameter -p port to a virtual machine, such as port 9000

docker run -d -p 9000:5000 training/webapp python app.py

4 We can be accessed via IP 192.168.12.249 port 9000 plus a virtual machine

 

4.1.23 release docker image to the warehouse

1 docker provides a similar github repository dockerhub, URL https://hub.docker.com/ need to register to use 2 registered docker id after login dockerhub in linux

docker login

Note To ensure that the image tag is the name of the account, if the mirror name does not need to change it tag

docker tag tiger/centos-vim richeryou/centos-vim

The syntax is: docker tag warehouse name lxh661314 / warehouse name

3 Push docker image to dockerhub

docker push richeryou/centos-vim:latest

4 Check the mirror dockerhub in https://hub.docker.com/ 5 delete local mirror, pull test image file download

docker rmi -f d69
docker pull richeryou/centos-vim

Mirror Mirror download and delete

 

5. private warehouse

5.1 private warehouse building

Private warehouse docker 5.1.1 official of the registry usage
https://yeasy.gitbooks.io/docker_practice/repository/registry.html
5.1.2 a command to download the image registry and start a private warehouse container
docker pull registry

Private repository will be created in the container / var / lib / registry, so -v parameters are stored by the image file to the local / opt / data / registry port mapping container port 5000 to port 5000 of the host

docker run -d -p 5000:5000 -v /opt/data/registry:/var/lib/registry registry
5.1.3 check the registry to start container
docker ps
5.1.4 Test Connection container
telnet 192.168.1.197 5000 ?
5.1.5 modify the image tag, beginning with docker registry of address port
docker tag qishi5/centos_vim 192.168.1.197:5000/qishi5_centos_vim
5.1.6 View docker mirror, the mirror to find the registry
docker images
5.1.7 Docker default does not permit a non-HTTPS mode push mirror. We can cancel this restriction by Docker configuration options, where you must write the correct json data
[root @ master /] # cat /etc/docker/daemon.json 
adding a line configuration
{
  "Registry-Mirrors": [ "http://f1361db2.m.daocloud.io"],
  "in the insecure-Registries": [ " 192.168.12.249:5000 "] # machine using the IP
}

Docker written into the service, write to [-Service] configuration block, this configuration file is loaded

vim /lib/systemd/system/docker.service

Add a line configuration

EnvironmentFile=-/etc/docker/daemon.json
5.1.8 docker modify the configuration file, reload docker
systemctl daemon-reload
5.1.9 restart docker
systemctl restart docker

Note restart docker service, all containers will hang

Note restart docker service, all containers will hang

Note restart docker service, all containers will hang

5.1.10 restart docker, registry container process just hung up, so restart it
docker ps -a
docker start 容器id
5.1.11 push local mirror
docker push 192.168.119.10:5000/hello-world
5.1.12 Since docker registry no web interface, but provides an API data

To see the image has been uploaded, you can see at the following link:

Official website tutorial: HTTPS: //docs.docker.com/registry/spec/api/#listing-repositories 
curl http://192.168.12.249:5000/v2/_catalog
or browser access http://192.168.12.249:5000 / v2 / _catalog # using the local IP
5.1.13 delete local mirror, download from private warehouse

To modify a mirror image of the label

docker qishi / CentOS-192.168.12.249:5000/qishi-centos-vim

Upload Mirror

docker push 192.168.12.249:5000/qishi-centos-vim

Delete local mirror

docker rmi -f `docker images -aq`

Download image

docker pull 192.168.12.249:5000/hello-world

6. Use dockerfile customized image

6.1 a simple shell script
cd / opt 
mkdir hehe2
cd hehe2
Touch hehe.py
echo "Print ( 'Oh your sister ah ~ ~ ~')"> hehe.py
python3 hehe.py
6.2 dockerfile basic use
1. FROM parameter (specified base image) 
the FROM Scratch # production base image Base image, the image as much as possible using the official image Base
the FROM # centos centos to as base image, secondary image constructed
FROM ubuntu: 14.04 # base with the tag Image 2. lABEL parameters (labels, definitions of information) lABEL Version = "1.0" # container meta-information, help, metadata, similar to the code comments lABEL = the Maintainer to "[email protected]" 3. RUN parameter (is a universal instruction, Run) # RUN command for complex, to avoid useless layered, multiple commands with a backslash line feed, a synthesis order! Update && yum yum the install the RUN -Y Vim \   the Python-dev # backslash wrap the RUN / bin / the bash -C "Source $ the HOME / .bashrc; $ echo the HOME" 4. the WORKDIR parameters (corresponding to the linux cd command) WORKDIR / root # equivalent of linux cd command to change directories, try to use absolute paths! ! ! Do not cd RUN WORKDIR / the Test # If you do not automatically create WORKDIR demo # re-entering the demo folder RUN pwd # print the results should be / test / demo

















5. ADD parameter (the host of a file, added to the container space)
the ADD /opt/django/manage.py / opt / # /opt/django/manage.py the host computer into the space within the container / under opt / directory
ADD /opt/python3.6.tar.gz / opt / # action ADD-extracting file, the host computer will python3.6.tar.gz / opt / under decompression to / opt / directory within the container under
the ADD and cOPY
the ADD hello / # to add local files to the mirror, it's hello local executable files are copied to the mirror / directory
ADD test.tar.gz / # added to the root directory and extract WORKDIR / root the ADD hello the Test / # enter / root / hello executable commands added to the test directory, that is, / root / test / hello an absolute path cOPY hello test / # is equivalent to the above-described effects ADD 6. cOPY parameters (copy instructions) # the host files are copied to the container, but no decompression command, try using the cOPY, do not use the ADD cOPY filename / opt / the ADD and cOPY   - priority using the cOPY command   -ADD addition cOPY features include decompression add remote file / directory the curl or wget 7. the ENV parameters (environmental parameters Docker instruction)















# ENV environment variable, using as much as possible to increase the maintainability ENV
ENV MYSQL_VERSION 5.6 # mysql provided a constant, similar to the $ {MYSQL_VERSION} global constants
RUN yum install -y mysql-server = "$ {MYSQL_VERSION}" # If the version number there is a change, you only need to change this constant on it
6.3   Use dockerfile custom django image

 



 

 

 

Guess you like

Origin www.cnblogs.com/youhongliang/p/12147331.html