Concepts
Images
- which are read only templates used to create containers.
- are created with the docker build command by docker user.
Containers
- container is an instance of an image(like an instance of a class - a runtime object)
Official Docker images website -> https://hub.docker.com/
Basic commands
ls本机上的docker image -> docker images
创建一个有busybox的的docker container 并执行 echo "hello docker"
-> docker run busybox:1.24 echo "hello docker"
ls docker container中的根目录 -> docker run busybox:1.24 ls /
进入docker container -> docker run -i -t busybox:1.24
,执行exit
可退出container,每一次都是一个新的image
使用docker ps -a
来查看创建过的历史container ->
1 | rx:dev reed$ docker ps -a |
新建一个container执行命令,完成后自动删除这个container -> docker run --rm busybox:1.24 sleep 1
新建一个指定名字的docker container -> run --name my_docker_container busybox:1.24 ls
inspect一个container的底层信息 ->
1 | rx:dev reed$ docker run -d busybox:1.24 sleep 100 |
拉取tomcat 8.0 image,并创建一个container,同时将container的8080端口映射到主机的8888端口 ->
- 从国内docker image源中下载tomcat 8.0 image ->
docker pull registry.docker-cn.com/library/tomcat:8.0
- 创建container并映射端口 ->
docker run -it -p 8888:8080 registry.docker-cn.com/library/tomcat:8.0
- 运行container并在后台运行 ->
docker run -it -d -p 8888:8080 registry.docker-cn.com/library/tomcat:8.0
执行后会显示container ID - 查看后台运行的container的运行log ->
docker logs DOCKER_CONTAINER_ID
- 停止一个后台运行的container ->
docker stop DOCKER_CONTAINER_NAME
Run Container in Foreground or Background
run container in foreground -> default mode
run container in background -> -d
(dispatch) option
建一个container在后台运行,并用ps
查看运行中的container ->
1 | rx:dev reed$ docker run -d busybox:1.24 sleep 1000 |