Docker Study Notes (3)-Docker images and warehouses
Images and warehouses
View and delete images
Image storage location/var/lib/docker
List Images
docker images [OPTIONS] [REPOSITORY]
-A,-all = false Show all images (default hides intermediate images)
-Digests = false Show digests
-F,-filter = [] Filter output based on conditions provided
-Help = false Print usage
-No-trunc = false Don't truncate output
-Q,-quiet = false Only show numeric IDs
Image Tag and repository
When running docker images, you can see:
PEROSITORY is the repository and TAG is the TAG.
View images
docker inspect [OPTIONS] CONTAINER|IMAGE [CONTAINER|IMAGE...]
-F,-format = Format the output using the given go template
-Help = false Print usage
-Type = Return JSON for specified type, (e. g image or container)
Delete an image
docker rmi [OPTIONS] IMAGE [IMAGE...]
-F,-force = false Force removal of the image
-Help = false Print usage
-No-prune = false Do not delete untagged parents
Retrieve and push images to search for images
docker search [image]
Pull Image
docker pull [image]
-A,-all-tags = false
Acceleration
Use the-registry-mirror Option
1. Modify:/etc/default/docker
2. Add: DOCKER_OPTIOS = "-registry-mirror = http: // XXXX"
Push Image
docker push
Build an image
Docker commitBuild through container
Docker buildDockerfileFile Construction
docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
-A,-author = Author (e.g., "John Hannibal Smith hannibal@a-team.com ")
-C,-change = [] Apply Dockerfile instruction to the created image
-Help = false Print usage
-M,-message = Commit message
-P,-pause = true Pause container during commit
Example:
docker run -d --name test_web -p 80:80 billvsme/web nginx -g "daemon off;"
Use Dockerfile to build an image
docker build [OPTIONS] PATH | URL | -
-No-cache = false Do not use cache when building the image
-Q,-quiet = false Suppress the verbose output generated
-T,-tag = Repository name (and optionally a tag) for the image
Example:
docker build -t ='billvsme/web' ./
View the image building process
docker history [image]
Dockerfile format
Note
# Comment
Command
FROM
FROM
FROM: The existing image base image must be the first non-Annotated instruction.
MAINTAINER
MAINTAINER
Specify the creator of the image to learn the commands run in the current image
RUN
RUN
(Shell mode) RUN echo hello RUN ["executable", "param1", "param2"] (exec mode) RUN ["/bin/bash", "-c ", "echo hellow"] EXPOSE specifies the container running port. It only tells docker that the container uses this port, but does not automatically open the port. Instead, it adds the port ing command to the run.
Example:
#First DockerfileFROM ubuntu:14.04MAINTAINER billvsme "994171686@qq.com"RUN apt-get updateRUN apt-get install -y nginxEXPOSE 80
Other commands
CMD
CMD command param1 param2 (shell mode) CMD ['executable', "param1", "param2"] (exec mode) CMD ['param1 ', 'param2'] (as the default parameter of the ENTERYPOINT command) The RUN Command runs during the container build. The CMD command runs when the container runs, if docker run specifies the cmd command, the CMD command will be overwritten.
ENTERYPOINT
ENTERYPOINT command param1 param2 (shell mode) ENTERYPOINT ['executable', "param1", "param2"] (exec mode) the difference with CMD is that ENTERYPOINT will not be overwritten, if you want to overwrite the data, you can use docker run -- entrypoint to overwrite the data.
COPY
COPY
...
COPY ["
"..."
"] (Applicable when there are spaces in the file path)
ADD
ADD is basically the same as COPY, but ADD provides a tar-like decompression function. ADD src can be a url
VOLUME
VOLUME ["/data"] adds a VOLUME to the container
WORKDIR
WORKDIR/path/to/workdir set the working directory inside the container. CMD and ENTERYPOINT will be executed in this directory.
ENV
ENV
ENV
=
... Set Environment Variables
USER
USER uidUSER uid: gidUSER uid: groupUSER nginx running as nginx is root by default
ONBUILD
ONBUILD [INSTRUCTION] image trigger: This trigger is executed when an image is used as a basic image by another image. When a sub-image is built, the trigger is inserted.