Creating an Nginx Image
Create a Docker image that is based on Nginx for deploying and running the Nginx service in the Docker container.
- Start Docker.
dockerd & ps -ef | grep docker
- Search for and download the image source.
- CentOS:
- openEuler 20.03:
1 2 3
docker search openeuler docker pull openeuler20/origin-pod:v3.11 docker images
In the actual environment, if the Internet is not available unless a proxy is configured, configure the environment variables of the proxy server and then configure Docker.
To configure the environment variables of the proxy server, perform the following operations:- Create a directory.
1mkdir /etc/systemd/system/docker.service.d/ - Create and edit the http-proxy.conf file.
1vim /etc/systemd/system/docker.service.d/http-proxy.conf - Press i to enter the insert mode and add the following content to the file. Replace the following parameters with the actual ones: youraccount indicates the user name and password indicates the password.
IP Address indicates the proxy IP address and PORT indicates the proxy port.
[Service] Environment="http_proxy=http://youraccount:password@IP Address:PORT"
- Press Esc, type :wq!, and press Enter to save the file and exit.
- Restart the server for the settings to take effect.
If the Internet is always not available, download the image to a server that can access the Internet and back up the image to the target server for deployment. The procedure is as follows:
- Visit the mirror site: https://mirrors.tools.huawei.com/openeuler/openEuler-22.03-LTS-SP1/docker_img/

- Download the Docker image based on the server architecture. The Docker image for the AArch64 architecture is used as an example.
- Upload the downloaded Docker image to the /home directory on the server.
- Load the image in Docker.
docker load -i /home/openEuler-docker.aarch64.tar.xz
or
docker load < /home/openEuler-docker.aarch64.tar.xz

- Check the loaded image.
docker images

- Create an image using the dockerfile.
- Create a dockerfile directory.
1mkdir /home/dockerfile - Copy the compiled and configured Nginx and its dependencies to the dockerfile directory.
- CentOS:
1 2 3 4 5 6 7
\cp -r /usr/local/nginx /home/dockerfile \cp -r /usr/lib64/perl5 /home/dockerfile \cp -r /usr/local/lib64/perl5 /home/dockerfile/perl5_1 \cp -r /usr/share/perl5 /home/dockerfile/perl5_2 \cp -r /usr/sbin/ifconfig /home/dockerfile \cp -r /usr/sbin/ethtool /home/dockerfile \cp -r /usr/bin/netstat /home/dockerfile
- openEuler:
1 2 3 4 5 6 7 8
\cp -r /usr/local/nginx /home/dockerfile \cp -r /usr/lib64/perl5 /home/dockerfile \cp -r /usr/lib64/perl5 /usr/local/lib64/ \cp -r /usr/local/lib64/perl5 /home/dockerfile/perl5_1 \cp -r /usr/share/perl5 /home/dockerfile/perl5_2 \cp -r /usr/sbin/ifconfig /home/dockerfile \cp -r /usr/sbin/ethtool /home/dockerfile \cp -r /usr/bin/netstat /home/dockerfile
- CentOS:
- Copy the sysctl.conf file on the physical machine to the dockerfile directory.
1\cp /etc/sysctl.conf /home/dockerfile
- Create an Nginx startup script.
- Create a start.sh script.
1vim /home/dockerfile/start.sh - Add the following content to the file:
sysctl -p /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
- Press Esc, type :wq!, and press Enter to save the file and exit.
- Create a start.sh script.
- Create a dockerfile file.
- Create a file.
1vi /home/dockerfile/dockerfile - Add the following content to the file:
- CentOS:
FROM centos:7 USER root WORKDIR /home/ COPY sysctl.conf /etc/ COPY nginx /usr/local/nginx COPY perl5 /usr/lib64/perl5 COPY perl5_1 /usr/local/lib64/perl5 COPY perl5_2 /usr/share/perl5 COPY ifconfig /usr/sbin/ COPY ethtool /usr/sbin/ COPY netstat /usr/sbin/ COPY start.sh /home/ RUN echo 'ulimit -n 102400' >> /etc/profile RUN chmod +x /home/start.sh CMD /home/start.sh && /usr/bin/top
- openEuler:
FROM openeuler20/origin-pod:v3.11 USER root WORKDIR /home/ COPY sysctl.conf /etc/ COPY nginx /usr/local/nginx COPY perl5 /usr/lib64/perl5 COPY perl5_1 /usr/local/lib64/perl5 COPY perl5_2 /usr/share/perl5 COPY ifconfig /usr/sbin/ COPY ethtool /usr/sbin/ COPY netstat /usr/sbin/ COPY start.sh /home/ RUN echo 'ulimit -n 102400' >> /etc/profile RUN chmod +x /home/start.sh CMD /home/start.sh && /usr/bin/top
- CentOS:
- Press Esc, type :wq!, and press Enter to save the file and exit.
For details about the command description, see Table 1.
The reason for running the /usr/bin/top command is as follows: The Docker containers are running in the background. A suspended command (such as top and tail) must exist. Otherwise, the containers automatically exit.
Table 1 Command description Command
Description
FROM
Creates an image based on the downloaded CentOS image.
USER
Runs the image as the root user.
WORDIR
The working directory is /home.
COPY
Copies the files in the dockerfile directory of the physical machine to the related directories in the container.
RUN
Runs related commands.
CMD
Runs the related scripts when the container is started.
- Create a file.
- Create an image.
- CentOS:
1 2 3
cd /home/dockerfile docker build -t arm/centos7/nginx:http . docker images | grep arm/centos7/nginx
- openEuler:
1 2 3
cd /home/dockerfile docker build -t arm/openeuler20/nginx:http . docker images | grep arm/openeuler20/nginx
- arm/centos7/nginx indicates the image name, and http indicates the tag.
- arm/openeuler20/nginx indicates the image name and http indicates the tag.
- "." indicates that the image is created using the dockerfile file in the current directory.
- CentOS:
- Create a dockerfile directory.
