Docker Getting Case

Docker use

docker is an open source application container engine, go language that allows developers to package their applications and dependencies based on a lightweight, portable container, and then completely posted to any Linux machine, can be virtualized of

Key concept

  • Docker host: machine Docker program installed

  • Docker client: via the command line or other tools Docker

  • Docker warehouse: to save all kinds of packaged software image

    • Central warehouse communal HUB

  • Docker Mirror: used to create containers

  • Docker containers: Example mirroring

First, the commonly used commands

# Start Service Docker 
Service Docker Start
# restart service
Service Docker restart
# stop service
Service Docker STOP
Mirror # container operations 
# http://hub.docker.com can view all mirrors
# mysql search image Docker
Docker mysql Search
# Docker pulling mysql mirror can be specified as a default version of the lastest
Docker pull mysql: 8.0.17
# View native mirror
docker ImagesRF Royalty Free
# delete docker container
docker RM [container container-or the above mentioned id-name]
# image delete docker
docker rmi [container-Image or the above mentioned id-name]
# docker container -a view of all all (with or without running)
docker PS -a
# New and operating parameters of the mirror
# t i pseudo terminal interface port mapping p d --name background container name P randomly mapped port
docker rUN -i -t -d -p 3306: 3306 MySQL
# directory into the container
docker the attach [container container--ID or name]
# run container
dockerStart [Container Container-or the above mentioned id-name]
# stop the container
Docker STOP [Container Container-or the above mentioned id-name]
# View container logs
# -f: Let docker logs the same as using the tail -f to standard output -e inside the container parameters to carry container
Docker logs -f [or container container-the above mentioned id-name]
# View port mapping
Docker port [container container-or the above mentioned id-name]
# can view the processes running in the container
Docker Top [container-the above mentioned id or Container- name]
# view the configuration of the container bottom returns a file json
Docker Inspect [container container-ID or-name]
# for copying data between the container and the host
Docker CP [path] [container container--ID or name]: [path]
Docker CP [container container--ID or name]: [path] [path]
# Release and closing the container / container exit
exit / Ctrl + P + Q

# Log MySQL
Docker Exec -it [Container-the above mentioned id] / bin / bash

Second, the data volume container

Similarly mount shared directory, data sharing between the container and the host, both data sharing of data volume (readable writable / specified)

Docker Expediting IT -v [/ host absolute path]: [/ directory within the container]: [RO (Read Only host can write, read-write host)] [Image-name] 
Docker Expediting IT -v / mydata -host: / mydata-container: ro tomcat

DockerFile

  • ockerfile is a text file that contains commands for the combined image. It can be used to call any command on the command line. Docker by reading the Dockerfileautomatic generation of image instructions.

    docker buildCommand is used to construct an image from Dockerfile. You can docker builduse command -fflag to the file system Dockerfile anywhere.

test.java ====>test.class

Docker images ========> DockerFile

 

docker bulid -f [dockerfile] -t [name]:[version]

Data volume container

  • Life name data volume container mount, another container shared by mounting the data (parent container), this data is called the parent container volume container

  • Data is transmitted to the parent sub-tank vessel through the data volume

docker run -it --name dc02 --volumes-from dc01 my-centos-image

Three, Dockerfile

Dockerfile execution

  • Reserved instruction word, capitalized, followed by at least one parameter must be

  • From top to bottom, the order of execution

  • # Denotes a comment

  • Each command will create a mirror

  • Docker run from a container base image

  • Execute an instruction and container make changes

  • Performs a similar operation docker commit to submit a new image

  • docker again based mirroring run just submitted a container

  • The next instruction execution Dockerfile know all instructions execute complete

Reserved word instruction

  • FROM base image based on this current mirror image building

  • MAINTAINER mirror maintainer name E-mail

  • Command needs to be run when building RUN container

  • EXPOSE port

  • WORKDIR landing the default directory container

  • ENV environment variable

  • ADD is added when building native file url and decompression may be processed

  • COPY can not handle decompression, and url with ADD

  • VOLUME data volumes

  • Run command CMD container, only after a function, replaces the last preceding input (parameter including entrained)

  • ENTRYOPOINT with CMD, will not replace but will append command

  • It will be triggered when ONBUILD parent mirror image constructed in quilt

 

Examples: centos6.8 -------------> Dockerfile

FROM scratch
MAINTAINER The CentOS Project <[email protected]>
ADD c68-docker.tar.xz /
LABEL name="CentOS Base Image" \
   vendor="CentOS" \
   license="GPLv2" \
   build-date="2016-06-02"

# Default command
CMD ["/bin/bash"]

 

Guess you like

Origin www.cnblogs.com/yangenyu/p/11740346.html