After I commited container to image,
I run container by saved image again and add option to publish the container’s port(8888).
Command list
- stop container
$ docker ps $ docker container stop work $ docker ps
- commit container to image
$ docker container commit -m "add python3.5 and jupyter notebook" work xxxxxxx/centos7:python3 $ docker images
- run container
$ docker container run -d --name work2 -p 18888:8888 xxxxxxx/centos7:python3 tail -f /dev/null $ docker ps $ docker exec -it work2 /bin/bash
Detail
[vagrant@localhost ~]$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 519dd98187dd centos:7 "tail -f /dev/null" 24 hours ago Up 24 hours work [vagrant@localhost ~]$ docker container stop work work [vagrant@localhost ~]$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [vagrant@localhost ~]$
[vagrant@localhost ~]$ docker container commit -m "add python3.5 and jupyter notebook" work xxxxxxx/centos7:python3 sha256:3b592921ad2461a03b734d11f75cf28d1c4ea29a17e5eff981e2165e87eaf15c [vagrant@localhost ~]$ docker images REPOSITORY TAG IMAGE ID CREATED SIZE xxxxxxx/centos7 python3 3b592921ad24 10 seconds ago 429 MB centos 7 67591570dd29 8 weeks ago 192 MB [vagrant@localhost ~]$
[vagrant@localhost ~]$ docker container run -d --name work2 -p 18888:8888 xxxxxxx/centos7:python3 tail -f /dev/null 479c57f04b63d747d076389f9522462d6332aa54d40f3e603cc431a78f081037 [vagrant@localhost ~]$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 479c57f04b63 xxxxxxx/centos7:python3 "tail -f /dev/null" 5 seconds ago Up 2 seconds 0.0.0.0:18888->8888/tcp work2 [vagrant@localhost ~]$ [vagrant@localhost ~]$ docker exec -it work2 /bin/bash [root@479c57f04b63 /]#