Docker directory
Article Directory
Preface
- This article is a quick
Docker
start, only enumerates thedocker
usage method - If necessary, please read official documents and related books
What is Docker?
- Because the configuration environment is different, the software in the development environment may not be used if it is moved to the operation and maintenance test machine;
- The reasons for not being able to use are: environment configuration, library called, etc.;
- Three elements of Docker: warehouse, mirror, container;
Docker installation
yum install -y epel-release
yum install -y docker-io
ll /etc/sysconfig/docker
service docker start /// systemctl start docker
docker version
View kernel version
uname -r
cat /etc/redhat-release
Docker architecture
client
—>Client, command terminal;docker_host
---->Server;repository
—>Remote warehouse;
Alibaba Cloud configuration
- open the Web page:
dev.aliyun.com/search.html
login
copy url
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<- 'EOF' xxxxEOF
vim /etc/sysconfig/docker
other_args="--registry-mirror=https://aa25jingu.mirror.aliyuns.com"
service docker restart
sudo systemctl daemon-reload
sudo systemctl restart docker
ps -ef | grep docker
run
docker run hello-world
docker help command
docker version
docker info
docker --help
docker image command
docker images
: List the mirrors on the local host
-a
: all-q
: Show mirror id--digests
: Summary information--no-trunc
: Display complete mirror information
docker search (options) [name]
-s
: List the number of collections not less than how many--automated
: Type of automatic build
docker pull
: download mirror
docker pull tomcat === docker pull tomcat:lastest
docker rmi [name]
Container command
docker pull centos
docker run [options] image [command]
--name
: New name;-d
:Background process-i
: Interactive operation-t
: Assign a pseudo input terminal to the container-P
:Port Mapping-p
: Specify port mapping
docker ps [options]
: List running containers-a
: List all-l
: Recently created-q
: Only display the number--no-trunc
: Do not truncate the output
Exit:exit
ctrl+P+Q
docker start [id / name]
docker restart [id / name]
docker stop [id / name]
docker kill [id / name]
docker rm [id]
docker rm -f ${docker ps -a -q}
docker ps -a -q | xargs docker rm
docker logs -f -t --tail
docker top
docker inspect [id]
: View the internal details of the container;docker exec -t [id] ls -l
: Perform command operations outside of dockerdocker cp [id]
: Destination host path of the path in the containerdocker attach 【id】
: Connect to the running container.
Mirror commit
docker commit -m="message" -a="author" [id] [name]:tag
docker ps
The container container after id=run ( ), not docker imagesdocker run -it -p 8888:8080 tomcat
docker run -it -P tomcat
Start in the background
docker run -d -p 6666:8080 tomcat
Container data volume
docker run -it -v [宿主机绝对路径目录:容器内目录] 镜像名
docker run -it -v [宿主机绝对路径目录:容器内目录]:ro 镜像名
- The host can be written, but the docker image can only be viewed
- The original intention is: data conversion;
Data volume container
- Active hard disk hanging active hard disk, to achieve data transfer dependence;
docker run -it --name dc01 zzyy/centos
docker run -it --name dc02 --volumes-from dc01 zzyy/centos
- Creating files in the same folder will achieve the effect of file sharing
docker rm -f dc01
- When 2, 3 inherits 1, delete 1 and it does not affect 2, 3;
- The transfer of configuration information between containers, the life cycle of the data volume continues until there is no container in use;
DockerFile
>Docker Image
>Docker run
DockerFile
Reserved word instruction
- FROM
- MAINTAINER
- RUN
- EXPOSE
- WORKDIR
- ENV
- ADD
- COPY
- VOLUME
- CMD
- ENTRYPOINT
- ONBUILD
FROM centos
- MAINAINER fwx<[email protected]>
#当前宿主机拷贝到容器目录下(/usr/local/)
COPY xx.txt /usr/local/xx.txt
#压缩文件添加并解压到容器里
ADD xx.tar.gz /usr/local
#安装tool
RUN yum -y install vim
#设置工作路径
ENV WORKPATH /usr/local
WORKDIR $WORKPATH
#启动时运行
CMD ll [只能执行最后一个,不能重叠.出现多个前面失效]
ENTRYPOINT ['ls', '-s']
Excuting an order
docker run -d -p 9080:8080 --name xx -v /usr/local:/tmp --privileged=true xx-name