构建镜像

通过容器构建镜像

heyongjindeMacBook-Pro:~ heyongjin$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
heyongjindeMacBook-Pro:~ heyongjin$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
27777cacc593 hello-world "/hello" 8 minutes ago Exited (0) 4 seconds ago gallant_leavitt
heyongjindeMacBook-Pro:~ heyongjin$ docker commit 27777cacc593 heyongjin1/hello-world
sha256:de6f7c09a2e05fbe25772d60f06ec31a1416f2f3ce20ea0092a4315b38732700
heyongjindeMacBook-Pro:~ heyongjin$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
heyongjin1/hello-world latest de6f7c09a2e0 8 minutes ago 1.84 kB
nginx/ubuntu latest c9d29082edfc 4 hours ago 290 MB
all/centos latest d3d766ed17fd 4 hours ago 265 MB
hello-world latest 48b5 124b2768 3 weeks ago 1.84 kB
ubuntu latest 104bec311bcd 7 weeks ago 129 MB
redis 3.0 dd0d72f99d5e 7 weeks ago 176 MB
mysql 5.5 0f8cd588fa9c 7 weeks ago 255 MB
nginx latest abf312888d13 2 months ago 182 MB
centos latest 0584b3d2cf6d 3 months ago 197 MB
tomcat 7.0.69 83f3f8af3613 8 months ago 353 MB

通过Dockerfile构建镜像

heyongjindeMacBook-Pro:~ heyongjin$ cd ~/Downloads/
heyongjindeMacBook-Pro:Downloads heyongjin$ mkdir docker
heyongjindeMacBook-Pro:Downloads heyongjin$ cd docker/
heyongjindeMacBook-Pro:docker heyongjin$ vim Dockerfile
heyongjindeMacBook-Pro:docker heyongjin$ cat Dockerfile
#First Dockerfile
FROM ubuntu
MAINTAINER heyongjin "[email protected]"
RUN apt-get update
RUN apt-get install -y nginx
EXPOSE 80
heyongjindeMacBook-Pro:docker heyongjin$ docker build -t='heyongjin1/ubuntu' .
Sending build context to Docker daemon 2.048 kB
///省略若干
Step 5/5 : EXPOSE 80
---> Running in 3229c49fc497
---> 92711ec95ccc
Removing intermediate container 3229c49fc497
Successfully built 92711ec95ccc
heyongjindeMacBook-Pro:docker heyongjin$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
heyongjin1/ubuntu latest 92711ec95ccc About an hour ago 225 MB
heyongjindeMacBook-Pro:docker heyongjin$ docker run -it --name='web1' -p 80 heyongjin1/ubuntu /bin/bash
root@fd6cd7308aff:/# curl localhost
curl: (7) Failed to connect to localhost port 80: Connection refused
root@fd6cd7308aff:/# nginx
root@fd6cd7308aff:/# curl localhost



Welcome to nginx!



Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

你可能感兴趣的:(构建镜像)