First, what is docker
Docker is an open source application container engine that lets developers can package their applications and dependencies into a portable mirror, and then publish to any of the popular Linux or Windows machine can be virtualized. The container is full use of the sandbox mechanism will not have any interface with each other.
Two, Docker installation
rpm (rhel) docker can be installed to the official website to find their own self-installing docker
here we are ready version docker18.06
open docker
[root@server1 docker]# systemctl start docker
View information on installing good docker
[root@server1 docker]# docker info
Third, add docker mirroring, and run
In the beginning we have to let everyone interested docker, we prepared a 2048 game, where as a mirror to show Docker
1. Add game2048 mirror
[root@server1 ~]# ls
docker game2048.tar
[root@server1 ~]# docker load -i game2048.tar
011b303988d2: Loading layer 5.05MB/5.05MB
36e9226e74f8: Loading layer 51.46MB/51.46MB
192e9fad2abc: Loading layer 3.584kB/3.584kB
6d7504772167: Loading layer 4.608kB/4.608kB
88fca8ae768a: Loading layer 629.8kB/629.8kB
Loaded image: game2048:latest
2. Check the docker's image
[root@server1 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
game2048 latest 19299002fdbe 2 years ago 55.5MB
Here we are only a mirror of course we just added game2048
3. Run docker Mirror
[root@server1 ~]# docker run -d -p 80:80 --name game game2048
f0a654b8735cc259ab552def3c7bc8e383df1819a558d273c2fdd26ea911b363
Note that we are here -d means running in the background, otherwise he will take up our end, if not to run in the background, -it parameters you can use, -name renaming is a way, or we mirrored not distinguish between the process, -p is doing an address mapping, so you can make use of our physical machines docker port
4. View mirror running
[root@server1 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f0a654b8735c game2048 "/bin/sh -c 'sed -i …" 2 minutes ago Up 2 minutes 0.0.0.0:80->80/tcp, 443/tcp game
如果要查看所有的运行镜像,包括暂停的镜像,同ps命令一样,加参数-a即可
5. Review the operation of specific information mirror
and we see this specific operation process mirrors, and startup scripts, generate ip, port number, etc. can be queried
6. browser to view docker
Fourth, some simple command docker's
1.docker allocation of ip
after docker run, the system automatically allocates a ip
2.docker version View
[root@server1 ~]# docker version
Client:
Version: 18.06.1-ce
API version: 1.38
Go version: go1.10.3
Git commit: e68fc7a
Built: Tue Aug 21 17:23:03 2018
OS/Arch: linux/amd64
Experimental: false
Server:
Engine:
Version: 18.06.1-ce
API version: 1.38 (minimum version 1.12)
Go version: go1.10.3
Git commit: e68fc7a
Built: Tue Aug 21 17:25:29 2018
OS/Arch: linux/amd64
Experimental: false
3.docker common commands
# docker load -i ubuntu.tar 导入镜像
# docker run -it --name vm1 ubuntu 创建容器(以ubuntu镜像为模板)
# docker ps 查看容器状态
# docker ps -a 查看容器状态(包括不活跃的容器)
# docker attach vm1 连接容器
# docker top vm1 查看容器进程
# docker logs vm1 查看容器指令输出 -f 参数可以实时查看
# docker inspect vm1 查看容器详情
# docker stats vm1 查看容器资源使用率
# docker diff vm1 查看容器修改
# docker stop vm1 停止容器
# docker start vm1 启动容器
# docker kill vm1 强制干掉容器
# docker restart vm1 重启容器
# docker pause/unpause vm1 暂停/恢复容器
# docker rm vm1 删除容器
Five, docker quickly build nginx server
1. Import images, create a container
2. Review the information vm1 container
3. The browser access
4. Write a default publishing page, and then copy it to the default publishing directory container ninx
[root@server1 ~]# cd /tmp/
[root@server1 tmp]# ls
[root@server1 tmp]# mkdir docker
[root@server1 tmp]# cd docker/
[root@server1 docker]# vim index.html
[root@server1 docker]# cat index.html
hello
[root@server1 docker]# docker cp index.html vm1:/usr/share/nginx/html
Browser Testing
The course can also be used to mount the way
[root@server1 docker]# docker cp index.html vm1:/usr/share/nginx/html
[root@server1 docker]# docker rm -f vm1
vm1
[root@server1 docker]# docker run -d --name vm1 -p 80:80 -v /tmp/docker/:/usr/share/nginx/html nginx -v挂载,:前面的为本地的文件,后面的是docker的文件目录
2c1c05f6d6118de5f00c809ea70586069a271252746b195cade83acf9a05bce9
[root@server1 docker]# vim index.html
[root@server1 docker]# cat index.html
hello
hello
hello
Browser Test:
Sixth, the use of docker to create an interactive container
We are all created in front of the container into the background, then we here to create an interactive container, we have to ubentu system image, for example
[root@server1 docker]# docker images ubuntu
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 07c86167cdc4 3 years ago 188MB
[root@server1 docker]# docker run -it --name vm2 ubuntu
root@d89d5ee155db:/# ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
root@d89d5ee155db:/# id
uid=0(root) gid=0(root) groups=0(root)
root@d89d5ee155db:/#
Interactive end
ctrl+pq 不停止容器,后台运行
ctrl+d 直接结束容器,释放内存
rm 删除容器
rmi 删除镜像