vim Dockerfile
FROM alpine:latest MAINTAINER brady CMD echo "hello world"
进行构建
docker build -t hello_docker .
[root@localhost dnmp_test]# ls [root@localhost dnmp_test]# vim Dockerfile [root@localhost dnmp_test]# docker build -t hello_docker . Sending build context to Docker daemon 2.048 kB Step 1/3 : FROM alpine:latest Trying to pull repository docker.io/library/alpine ... latest: Pulling from docker.io/library/alpine 9d48c3bd43c5: Pull complete Digest: sha256:72c42ed48c3a2db31b7dafe17d275b634664a708d901ec9fd57b1529280f01fb Status: Downloaded newer image for docker.io/alpine:latest ---> 961769676411 Step 2/3 : MAINTAINER brady ▽ ---> Running in f1802f56a693 ---> 00cdf7104f8b Removing intermediate container f1802f56a693 Step 3/3 : CMD echo "hello world" ---> Running in e7b7a18d8c32 ---> baa4664fe58d Removing intermediate container e7b7a18d8c32 Successfully built baa4664fe58d [root@localhost dnmp_test]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello_docker latest baa4664fe58d 6 seconds ago 5.58 MB nginx-fun latest 6ea0e8bb024d 7 minutes ago 126 MB docker.io/nginx latest ab56bba91343 8 days ago 126 MB docker.io/alpine latest 961769676411 4 weeks ago 5.58 MB [root@localhost dnmp_test]# docker run hello_docker hello world
推送到远程
[root@localhost docker]# ls Dockerfile [root@localhost docker]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello_docker latest c4ea4dd5f8f9 2 minutes ago 5.59MB alpine latest e7d92cdc71fe 5 weeks ago 5.59MB [root@localhost docker]# docker commit -a brady -m "hello docker" c4ea4dd5f8f9 yeves/hello_docker Error response from daemon: No such container: c4ea4dd5f8f9 [root@localhost docker]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [root@localhost docker]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 59d586c17da1 hello_docker "/bin/sh -c 'echo "h…" 2 minutes ago Exited (0) 2 minutes ago musing_shamir 9b8fe3409f62 hello_docker "/bin/sh -c 'echo "h…" 2 minutes ago Exited (0) 2 minutes ago festive_nightingale [root@localhost docker]# docker commit -a brady -m "hello docker" 59d586c17da1 yeves/hello_docker sha256:315c59b50d02e0617d9249300f0f2f54fb929d4dcda124e71a07c87864455bcc [root@localhost docker]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE yeves/hello_docker latest 315c59b50d02 6 seconds ago 5.59MB hello_docker latest c4ea4dd5f8f9 3 minutes ago 5.59MB alpine latest e7d92cdc71fe 5 weeks ago 5.59MB [root@localhost docker]# docker login Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one. Username: yeves Password: WARNING! Your password will be stored unencrypted in /root/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded [root@localhost docker]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE yeves/hello_docker latest 315c59b50d02 49 seconds ago 5.59MB hello_docker latest c4ea4dd5f8f9 4 minutes ago 5.59MB alpine latest e7d92cdc71fe 5 weeks ago 5.59MB [root@localhost docker]# docker tag 315c59b50d02 yeves/hellow_docker:v1.0 [root@localhost docker]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE yeves/hello_docker latest 315c59b50d02 About a minute ago 5.59MB yeves/hellow_docker v1.0 315c59b50d02 About a minute ago 5.59MB hello_docker latest c4ea4dd5f8f9 4 minutes ago 5.59MB alpine latest e7d92cdc71fe 5 weeks ago 5.59MB [root@localhost docker]# docker push yeves/hello_docker:v1.0 The push refers to repository [docker.io/yeves/hello_docker] tag does not exist: yeves/hello_docker:v1.0 [root@localhost docker]#