Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The actual combat of constructing Docker image

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

1. Docker to build nginx image

1. Create a working directory

Mkdir nginx/ / create nginx directory cd nginx/ all the following files related to nginx should be placed in this directory

2. Write dockerfile image production file

Vi Dockerfile / / write dockerfile files

# based on basic image

FROM centos

# user Information

MAINTAINER this is nginx image

# add an environment package

RUN yum install-y wget proc-devel net-tools gcc zlib zlib-devel make openssl-devel

# download nginx package

RUN wget http://nginx.org/download/nginx-1.9.7.tar.gz

RUN tar zxvf nginx-1.9.7.tar.gz

# specify a working directory

WORKDIR nginx-1.9.7

RUN. / configure-- prefix=/usr/local/nginx & & make & & make install

# specify http and https ports

EXPOSE 80

EXPOSE 443

# close the daemon

RUN echo "daemon off;" > > / usr/local/nginx/conf/nginx.conf

WORKDIR / root/nginx

# add run.sh from the host to the container

ADD run.sh / run.sh

RUN chmod 755 / run.sh

CMD ["/ run.sh"]

3. Make nginx startup script

Vi run.sh / / make nginx startup script

#! / bin/bash

/ usr/local/nginx/sbin/nginx

4. Create a new image

Docker build-t nginx:new.

5. Start the image and verify it

Docker run-d-P nginx:new

Visit the web page to visit 192.168.80.100purl 32769

2. Docker to build tomcat image

1. Create a new tomcat working directory

Mkdir / root/tomcat / / create directory cd tomcat/

2. Upload jdk and tomcat software packages

Tar xf jdk-8u144-linux-x64.tar.gz / / decompress the uploaded jdk environment tar xf apache-tomcat-8.5.23.tar.gz / / decompress and upload the tomcat package

3. Write dockerfile image production file

Vi Dockerfile

# based on basic image

FROM centos

# user Information

MAINTAINER this is tomcat image

# add jdk environment to the container

ADD jdk1.8.0_114 / usr/local/java

# configure the java environment in the container

ENV JAVA_HOME / usr/local/java

ENV JAVA_BIN / usr/local/java/bin

ENV JRE_HOME / usr/local/java/jre

ENV PATH $PATH:/usr/local/java/bin:/usr/local/java/jre/bin

ENV CLASSPATH / usr/local/java/jre/bin:/usr/local/java/lib:/usr/local/java/jre/lib/charsets.jar

# add a tomcat project to the container

ADD apache-tomcat-8.5.23 / usr/local/tomcat8

EXPOSE 8080

4. Create a new image

Docker build-t tomcat:centos.

5. Start the image and verify it

Docker run-d-- name tomcat01-p 8014 tomcat:centos

Web page visit 192.168.80.100

3. Docker to build a mysql image (centos6 is recommended)

1. Create a mysql working directory

Mkdir mysql / / create a mysql directory

2. Write dockerfile image production file

Vi Dockerfile

# based on basic image

FROM guyton/centos6

# user Information

MAINTAINER this is msyql images

# install mysql

RUN yum-y install mysql mysql-server

# start mysql and authorize login users

RUN / etc/init.d/mysqld start & &\

Mysql-e "grant all privileges on. To 'root'@'%' identified by' abc123';" & &\

Mysql-e "grant all privileges on. To 'root'@'localhost' identified by' abc123';"

# specify the mysql port in the container

EXPOSE 3306

# start daemon

CMD ["mysqld_safe"]

3. Create a new image

Docker build-t centos6:mysql.

4. Start the image

Docker run-name=mysqlserver-d-P centos6:mysql

5. Verify through the host

Yum install mariadb / / Host installs the mysql client program mysql-uroot-pabc123-h 192.168.80.100-P 32770 / / accesses the database in docker

Delete none images and invalid containers

In the process of creating an image, an none image will appear if an error is reported by dockfile, and a container with a status of Exited will appear when starting the image. These images and containers cannot be run, but will take up system space resources, so you need to clear them if necessary.

Vi none.sh / / write shell script

Add the following

Docker ps-a | grep "Exited" | awk'{print $1}'| xargs docker stop / / stop the container

Docker ps-a | grep "Exited" | awk'{print $1}'| xargs docker rm / / Delete the container

Docker images | grep none | awk'{print $3}'| xargs docker rmi / / Delete none image

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report