Docker containers Basic Operation
Initial start-Docker container command
docker run -d(后台运行容器) -p 8080:8080(绑定端口) xiaopang/centos-nodejs-1
Explanation:
By docker run first query from a local mirror if there is this, if there is a direct start of this mirror, if there is no mirror, download the image directly from the official mirror, and start the container
Start a stopped Docker container command
docker start eab4ad610972(容器ID)
View Docker container running
docker ps
See all stop running or container
docker ps -a
Stop Docker container
docker stop eab4ad610972(容器ID)
View Docker container running log
docker logs -f eab4ad610972(容器ID)
Delete Docker container has been stopped
docker rm eab4ad610972(容器ID)
Login container (similar to ssh)
docker exec -it eab4ad610972(容器ID) bash(执行的命令)
Loading container with volume data
docker run -p 8080:8080 -d --mount source=my-vol,target=/webapp centos-nodejs:1.0
[root@localhost ~]# docker run -p 8080:8080 -d --mount source=my-vol,target=/webapp centos-nodejs:1.0
5f73feb5e99a215255d0b95bce5cb5ef08549c5121af11afce63a4618acadce3
Mount View information containers
docker inspect 5f73feb5e99a
"Mounts": [
{
"Type": "volume",
"Source": "my-vol",
"Target": "/webapp"
}
],
To delete a data volume is not in use
docker volume rm my-vol
[root@localhost ~]# docker volume rm my-vol
Error response from daemon: remove my-vol: volume is in use - [5f73feb5e99a215255d0b95bce5cb5ef08549c5121af11afce63a4618acadce3]
Clean up all data volumes not occupied
docker volume prune
[root@localhost ~]# docker volume prune
WARNING! This will remove all local volumes not used by at least one container.
Are you sure you want to continue? [y/N] y
Total reclaimed space: 0B
Docker warehouse
Public warehouse
Docker hub registration
Docker hub Registered Address: https://hub.docker.com/
Search Mirror
docker search centos
Mirror Pull
docker pull centos
Login public warehouse
docker login
Push mirrored to a total warehouse
- Give your image tagging
docker tag centos-nodejs:1.0 xiaohai0407/centos-nodejs:1.0
- Check the label to lay a local mirror
docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
centos-nodejs 1.0 88fbf99d311d 3 minutes ago 343MB
xiaohai0407/centos-nodejs 1.0 88fbf99d311d 3 minutes ago 343MB
centos latest 5182e96772bf 8 days ago 200MB
ubuntu latest 735f80812f90 2 weeks ago 83.5MB
- Upload a mirror image library official to docker
docker push xiaohai0407/centos-nodejs
[root@localhost first]# docker push xiaohai0407/centos-nodejs
The push refers to repository [docker.io/xiaohai0407/centos-nodejs]
c1f3e6373b76: Pushed
bdba1884d9f2: Pushed
a37663980625: Pushed
2efbd85d8018: Pushed
1d31b5806ba4: Mounted from library/centos
1.0: digest: sha256:9c0fef1f79934c6a102437b3e0c6da61e48be61a0ce6f0d11cc157fb1a53704b size: 1362
- To see if the image is successfully uploaded
[root@localhost first]# docker search xiaohai0407
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
xiaohai0407/centos-nodejs base of centos 7 ,create nodejs hello word 0
Private warehouse
Private warehouse installation
docker run -d -p 5000:5000 -v /opt/data/registry:/var/lib/registry registry
[root@localhost ~]# docker run -d \
> -p 5000:5000 \
> -v /opt/data/registry:/var/lib/registry \
> registry
Unable to find image 'registry:latest' locally
latest: Pulling from library/registry
4064ffdc82fe: Pull complete
c12c92d1c5a2: Pull complete
4fbc9b6835cc: Pull complete
765973b0f65f: Pull complete
3968771a7c3a: Pull complete
Digest: sha256:20bbbc0f6384cf7dc6e292ccbe75935b73c92ec776543c970904bc60feceb129
Status: Downloaded newer image for registry:latest
36d7fb0a86534d32eb7f5c4090ebb5db35e801822433fb8138bf94db55477240
The storage path provided by the private repository -v parameter
to the / opt / data / registry path
Upload a mirror to a private warehouse
Mark mirrored to a private warehouse
docker tag ubuntu:latest 127.0.0.1:5000/centos-nodejs:1.0
Upload a mirror to a private warehouse
docker push 127.0.0.1:5000/centos-nodejs:1.0
[root@localhost registry]# docker push 127.0.0.1:5000/centos-nodejs:1.0
The push refers to repository [127.0.0.1:5000/centos-nodejs]
268a067217b5: Pushed
c01d74f99de4: Pushed
ccd4d61916aa: Pushed
8f2b771487e9: Pushed
f49017d4d5ce: Pushed
1.0: digest: sha256:958eaeb7e33e6c4f68f7fef69b35ca178c7f5fb0dd40db7b44a8b9eb692b9bc5 size: 1357
Check the warehouse already uploaded image
curl 127.0.0.1:5000/v2/_catalog
[root@localhost registry]# curl 127.0.0.1:5000/v2/_catalog
{"repositories":["centos-nodejs"]}
Repository already contains centos-nodejs the tag image file
Delete local mirror
docker image rm 127.0.0.1:5000/centos-nodejs:1.0
[root@localhost registry]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
centos-nodejs 1.0 88fbf99d311d 24 hours ago 343MB
xiaohai0407/centos-nodejs 1.0 88fbf99d311d 24 hours ago 343MB
centos latest 5182e96772bf 9 days ago 200MB
ubuntu latest 735f80812f90 2 weeks ago 83.5MB
registry latest b2b03e9146e1 5 weeks ago 33.3MB
[root@localhost registry]#
Download image from a local warehouse
docker pull 127.0.0.1:5000/centos-nodejs:1.0
[root@localhost registry]# docker pull 127.0.0.1:5000/centos-nodejs:1.0
1.0: Pulling from centos-nodejs
Digest: sha256:958eaeb7e33e6c4f68f7fef69b35ca178c7f5fb0dd40db7b44a8b9eb692b9bc5
Status: Downloaded newer image for 127.0.0.1:5000/centos-nodejs:1.0
[root@localhost registry]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
centos-nodejs 1.0 88fbf99d311d 24 hours ago 343MB
xiaohai0407/centos-nodejs 1.0 88fbf99d311d 24 hours ago 343MB
centos latest 5182e96772bf 9 days ago 200MB
127.0.0.1:5000/centos-nodejs 1.0 735f80812f90 2 weeks ago 83.5MB
ubuntu latest 735f80812f90 2 weeks ago 83.5MB
registry latest b2b03e9146e1 5 weeks ago 33.3MB