Mirror and related instruction obtaining Docker

Docker takes a snapshot

docker pull ubuntu: 16.04 command did not give an address Docker mirror warehouse, so will get image from Docker Hub.

Mirror Display: docker image ls

Run
docker run -it --rm ubuntu: 16.04 bash
running on ubuntu: 16.04 start a container
-it runs in the form of interactive container
 long command line breaks
--rm exit the container automatically removes the container
to exit the container exit Ctrl + D

Containers docker ps to see running
to see all of the containers docker ps -a

Update image docker pull ubuntu16.04 that is once again pull

Volume Mirroring

Dangling mirror: the mirror neither the warehouse name, there is no label, are
The reason is that by the time docker pull and docker build, because the official mirror maintenance release a new version, the original image is escaped downloaded image to a new body, and the name of the old image is canceled.
The following command may be used such image is to be displayed exclusively

For users Centos / RHEL is, in the case where there is no way to use UnionFSd, must be arranged to direct-lvm devicemapper, both for performance, stability or space utilization.

docker image rm ubuntu16.04; puncturing containers
docker rmi puncturing mirror image id

Dockerfile
Dockerfile script this script to build, customize carried
Dockerfile is a text file that contains the instructions within a section, each instruction to build a layer

pull Tomcat Docker
Docker ImagesRF Royalty Free
Docker Image LS
Docker RUN -it Tomcat bash
At this path: / usr / local / Tomcat
LS -al
own installed software must be installed in / usr / local

cd webapps ll
cd ROOT/
ls -al

echo "hello" > test.txt

docker run -8080:8080 tomcat

docker ps
docker ps -a

docker rm container id

docker images
docker run -p 8080:8080 tomcat

from tomcat to file the first line of
all dockerfile script must have a base image
run <command> <angle brackets must be filled>

docker run -it --rm tomcat bash
ls -al 
cd webapps/ 
cd ROOT/
ls -al
pwd

Create a directory under / usr / local / Docker
mkdir Tomcat
cd Tomcat /
LL
vi Dockerfile
the FROM Tomcat
RUN echo "the Hello Docker"> /usr/local/tomcat/webapps/ROOT/index.html

cat Dockerfile

Written script to start building Mirror

docker build -t shop .

Which. Shows the construction of the current directory, mirroring the current directory needs to be based dockerfile

docker run -it shop bash
ls -al
cd webapps/
ls -al
cd ROOT/
ls -al
cat index.html

ROOT directory delete all the files
vi Dockerfile

FROM tomcat 
RUN cd /usr/local/tomcat/webapps/ROOT/
RUN rm -fr *
RUN echo "Hello Docker" > /usr/local/tomcat/webapps/ROOT/index.html

Error, and the ROOT directory is also deleted,
Docker ImagesRF Royalty Free

vi Dockerfile

FROM tomcat 
WORKDIR cd /usr/local/tomcat/webapps/ROOT/
RUN rm -fr *
RUN echo "Hello Docker" > /usr/local/tomcat/webapps/ROOT/index.html

docker run -it --rm shop bash

ls -al
docker image prune
docker rmi imageID

Container is image-based
first exit container
Docker PS
Docker PS -a
Docker PS imageID

docker build -t mysql.
Looking Dockfile mirror construct a context (Context)

CD / usr / local / Docker /
LL
RM MySQL -fr /
LL
CD COM
RM -fr the ROOT /
LL
CD Tomcat /
operation docker build -t shop host HOST OS on
the current directory packaged RESTAPI request, also with this directory archive,
Docker Docker build Server receives the decompressed image Construction

COPY ./package.json / app /
This is not to be copied in the directory execute package.json docker build command, not a copy package.json directory DOckerfile lies, but copy package in context (context) directory. json. The source file path command is a relative path

To copy index.html

FROM tomcat
COPY index.html /usr/local/tomcat/webapps/ROOT/

docker build -t shop .

docker run -it --rm shop bash

Learning to have purpose, the fastest way to complete the task

Deploy the project to Docker containers

  1. Copy shop.zip -> tomcat / webapps / ROOT /
  2. Modify the access port 80

we Dockerfile

FROM tomcat
COPY shop.zip /usr/local/tomcat/webapps/ROOT
RUN unzip shop.zip
    

WORKDIR working directory, if the directory does not exist, WORKDIR will help you create a directory
for each command will build a hierarchical
every RUN is to start a container, even if you lose, start, and will not lead to direct deleted images, so you need to go back to delete the container and then delete the mirror under normal circumstances, - rm will be automatically deleted

we Dockerfile

FROM tomcat
WORKDIR /usr/local/tomcat/webapps/ROOT
RUN rm -fr *
COPY shop.zip .
RUN unzip shop.zip

:wq!

build -t shop .

After unzipping also requires a command
vi Dockerfile

FROM tomcat
WORKDIR /usr/local/tomcat/webapps/ROOT
RUN rm -fr *         #删除ROOT目录下所有内容
COPY shop.zip .
RUN unzip shop.zip
RUN rm -fr shop.zip
WORKDIR /usr/local/tomcat  #切换到镜像本身的工作空间

:wq!

build -t shop .

The nature and format of the COPY and ADD instructions are basically the same ADD instruction will automatically decompress the file to <destination path> go

we Dockerfile

FROM tomcat
WORKDIR /usr/local/tomcat/webapps/ROOT
RUN rm -fr *         
ADD shop.tar.gz .
WORKDIR /usr/local/tomcat

:wq!

docker build -t shop.
you can see that he is the whole package directories become more and more volume

docker run -it --rm shop bash

webapps cd /
cd ROOT /
LS -al
can see automatically decompressed, and the original tar package has been deleted
, but in some cases, if we really want to copy a compressed file in, and understand compression, which when you can not use the ADD command.

Next is to modify the port number is 80
Docker Image Prune

docker run -p 8080:8080 tomcat

-p means

EXPOSE <port 1> [<port 2> ...]
EXPOSE command just a statement, and this statement will not use this service port will open runtime.
In dockerfile written such a statement has two advantages, one assist users to understand the scene Guardian port services in order to facilitate the configuration map; Another advantage is that when you use the port mapping operation, that is,
docker run - when p, it will be automatically mapped EXPOSE random port

CMD [2 parameters, parameter 2 ...]
a container is a process, a program
setting parameters such as setting the placeholder script $ 1, $ 2

test.sh
SET PATH=$1

test.sh / usr / local / tomcat
wherein the / usr / local / tomcat is the path parameter passed
as passed the restart three parameters STOP RUN successful catalina.sh, then there is in catalina.sh three placeholder

Guess you like

Origin www.cnblogs.com/cgy-home/p/11203669.html