编程知识 cdmana.com

Dockerfile creation

Dockerfile establish

                        #Dockerfile  establish 

# Delete batch delete none Mirror image 
vim none.sh
docker ps -a | grep "Exited"|awk '{print $1}'|xargs docker stop
docker ps -a | grep "Exited"|awk '{print $1}'|xargs docker rm
docker images| grep none|awk '{print $3}'|xargs docker rmi

# One : ----------------------------- Three ways to create a mirror image 
##### Three ways to create a mirror image 
##1.Dockerfile
mkdir apache && cd apache

cat > Dockerfile <<-'EOF'
#1. Based on the basic image 
FROM centos:7
#2. Maintain the user information of the image 
MAINTAINER this is kgc
#3. to update yum Source , install httpd
RUN yum -y update           " New container , Use yum Update in advance yum Source "
RUN yum install -y httpd
#4. Expose the internal port of the container 
EXPOSE 80
#5. Copy the home page of the website 
ADD index.html /var/www/html/index.html
#6. Copy the execution script to the image 
ADD run.sh /run.sh
RUN chmod 755 /run.sh
#7. The script executed when the container is started 
CMD ["/run.sh"]
EOF

## Create a mirror image  " At the end of . Be sure to have "
docker build -t httpd:centos .
## New image run container 
docker run -d -p 8081:80 httpd:centos
##
echo "web test" > index.html 

tee run.sh <<EOF
#!/bin/bash
rm -rf /run/httpd/*
exec /usr/sbin/apachectl -D FOREGROUND
EOF

## test 
http://192.168.100.200:8081

##2. Create an image based on an existing container 
docker create -it centos:7 /bin/bash
docker ps
5e2e8a827d0d        httpd:centos        "/run.sh"                9 hours ago         Up 6 minutes        0.0.0.0:8081->80/tcp     dreamy_knuth
docker commit -m "ceshi" -a "li" 5e2e8a827d0d  tang:centos 
'//-m: Explanatory text ,-a: The author of the submission '

##3.  Create images based on local templates 
wget http://download.openvz.org/template/precreated/debian-7.0-x86-minimal.tar.gz
ls
    debian-7.0-x86-minimal.tar.gz 
cat debian-7.0-x86-minimal.tar.gz | docker import - daoke:new
docker images
    daoke                        new                 48335eb7b82d        13 seconds ago      215MB

# Two : ------------------------------ Private Warehouse Establishment 

##1. obtain registory Mirror image , Building warehouse containers 
docker pull registry  " Every private warehouse uses this image "
vim /etc/docker/daemon.json
"insecure-registries":["192.168.100.200:5000"],
systemctl restart docker.service

###2. The host machine /data/registory  Automatically create... In the mount container /tmp/registory
docker run -d -p 5000:5000 -v /data/registry:/tmp/registry registry
###3. Change mark to 192.168.100.150:5000/nginx
docker tag nginx:latest 192.168.100.200:5000/nginx
###4. Upload image to private warehouse 
docker push 192.168.100.200:5000/nginx
###5. Get the list of private warehouses 
curl -XGET http://192.168.100.200:5000/v2/_catalog

###6. Show upload success 
    {"repositories":["nginx"]}
###7. Test private repository downloads 

docker pull 192.168.100.200:5000/nginx

# 3、 ... and : --------------------------------------- Data volume management 

#1.-----------Docker Data volume ( Between host and container )
docker pull centos
## Host Directory /var/www Mount the... In the container /data1
docker run -v /var/www:/data1 --name web1 -it centos:7 /bin/bash
## Create data test in container 
cd /data1/
touch test123
## Return to the host computer to check 
ls /var/www/

#2.------------ Data volume container ( Container room )
## Data volume container 
docker run --name web100 -v /data1 -v /data2 -it centos:7 /bin/bash
## New container mount data volume container 
docker run -it --volumes-from web100 --name web99 centos:7 /bin/bash    "web99 Container name "
## Create files in two directories , test 

#-------------- Port mapping 
docker run -d -P httpd:centos
docker run -d -P 49280:80 httpd:centos
docker ps -a

#3. ----------- Container interconnection ( Use centos Mirror image )
##### Create and run container name web1, Automatic port number mapping 
docker run -itd -P --name web11 centos:7 /bin/bash
##### Create and run container name web12 , Connect to web1 Communicate with it 
docker run -itd -P --name web12 --link web11:web11 centos:7 /bin/bash
##### Get into web12 Containers  
ping web11

版权声明
本文为[osc_t4kk3au7]所创,转载请带上原文链接,感谢

Scroll to Top