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

What is the method of installing Nginx in Docker

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

Share

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

This article introduces what is the method of installing Nginx in Docker. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

Method 1. Build through Dockerfile

Create Dockerfile

First, create the directory nginx, which will be used to store the following related things.

[root@huixuan] # mkdir-p / nginx/www ~ / nginx/logs ~ / nginx/conf

[root@huixuan ~] # ls

Anaconda-ks.cfg Dockerfile nginx vpd.properties

[root@huixuan ~] #

The www directory will be mapped to the virtual directory configured by the nginx container

The logs directory will map to the log directory of the nginx container

The configuration file in the conf directory will be mapped to the configuration file of the nginx container

Enter the created nginx directory and create the Dockerfile

[root@huixuan nginx] # cat Dockerfile

FROM debian:jessie

MAINTAINER NGINX Docker Maintainers "docker-maint@nginx.com"

ENV NGINX_VERSION 1.10.1-1~jessie

RUN apt-key adv-keyserver hkp://pgp.mit.edu:80-recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62\

& & echo "deb http://nginx.org/packages/debian/ jessie nginx" > > / etc/apt/sources.list\

& & apt-get update\

& & apt-get install--no-install-recommends-no-install-suggests-y\

Ca-certificates\

Nginx=$ {NGINX_VERSION}\

Nginx-module-xslt\

Nginx-module-geoip\

Nginx-module-image-filter\

Nginx-module-perl\

Nginx-module-njs\

Gettext-base\

& & rm-rf / var/lib/apt/lists/*

# forward request and error logs to docker log collector

RUN ln-sf / dev/stdout / var/log/nginx/access.log\

& & ln-sf / dev/stderr / var/log/nginx/error.log

EXPOSE 80 443

CMD ["nginx", "- g", "daemon off;"]

[root@huixuan nginx] #

Create an image through Dockerfile and replace it with your own name

[root@huixuan nginx] # docker build-t nginx.

Sending build context to Docker daemon 4.608 kB

Step 1/7: FROM debian:jessie

Trying to pull repository docker.io/library/debian...

Jessie: Pulling from docker.io/library/debian

3d77ce4481b1: Pull complete

Digest: sha256:f29d0c98d94d6b2169c740d498091a9a8545fabfa37f2072b43a4361c10064fc

Status: Downloaded newer image for docker.io/debian:jessie

-- > 4eb8376dc2a3

Step 2 docker-maint@nginx.com 7: MAINTAINER NGINX Docker Maintainers "docker-maint@nginx.com"

-- > Running in 805eb7f2e4e8

-- > 1c1e36615d27

Removing intermediate container 805eb7f2e4e8

Step 3ax 7: ENV NGINX_VERSION 1.10.1-1~jessie

-- > Running in d86befe384a8

-- > f559945b9860

Removing intermediate container d86befe384a8

Step 4 no-install-recommends 7: RUN apt-key adv-keyserver hkp://pgp.mit.edu:80-recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 & & echo "deb http://nginx.org/packages/debian/ jessie nginx" > > / etc/apt/sources.list & & apt-get update & & apt-get install--no-install-recommends-no-install-suggests-y ca-certificates nginx=$ {NGINX_VERSION} nginx-module-xslt nginx-module-geoip nginx-module-image-filter nginx-module-perl nginx- Module-njs gettext-base & & rm-rf / var/lib/apt/lists/*

-- > Running in 273e2e414e8f

Executing: gpg-ignore-time-conflict-- no-options-- no-default-keyring-- homedir / tmp/tmp.AEdkYzmRAy-- no-auto-check-trustdb-- trust-model always-- primary-keyring / etc/apt/trusted.gpg-- keyring / etc/apt/trusted.gpg.d/debian-archive-jessie-automatic.gpg-- keyring / etc/apt/trusted.gpg.d/debian-archive-jessie-security-automatic.gpg-- keyring / etc/apt/trusted.gpg.d / debian-archive-jessie-stable.gpg-keyring / etc/apt/trusted.gpg.d/debian-archive-stretch-automatic.gpg-keyring / etc/apt/trusted.gpg.d/debian-archive-stretch-security-automatic.gpg-keyring / etc/apt/trusted.gpg.d/debian-archive-stretch-stable.gpg-keyring / etc/apt/trusted.gpg.d/debian-archive-wheezy-automatic.gpg-keyring / etc/apt/trusted.gpg.d/debian- Archive-wheezy-stable.gpg-keyserver hkp://pgp.mit.edu:80-recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62

Gpg: requesting key 7BD9BF62 from hkp server pgp.mit.edu

Gpg: key 7BD9BF62: public key "nginx signing key" imported

Gpg: Total number processed: 1

Gpg: imported: 1 (RSA: 1)

Get:1 http://nginx.org jessie InRelease [2856 B]

Ign http://deb.debian.org jessie InRelease

Get:2 http://deb.debian.org jessie-updates InRelease [145 kB]

Get:3 http://security.debian.org jessie/updates InRelease [94.4 kB]

Get:4 http://nginx.org jessie/nginx amd64 Packages [12.6 kB]

Get:5 http://security.debian.org jessie/updates/main amd64 Packages [647 kB]

Get:6 http://deb.debian.org jessie Release.gpg [2434 B]

Get:7 http://deb.debian.org jessie-updates/main amd64 Packages [23.1 kB]

Get:8 http://deb.debian.org jessie Release [148 kB]

Get:9 http://deb.debian.org jessie/main amd64 Packages [9064 kB]

Fetched 10.1 MB in 1min 53s (89.3 kB/s)

Reading package lists...

Reading package lists...

Building dependency tree...

Reading state information...

Some packages could not be installed. This may mean that you have

Requested an impossible situation or if you are using the unstable

Distribution that some required packages have not yet been created

Or been moved out of Incoming.

The following information may help to resolve the situation:

The following packages have unmet dependencies:

Nginx-module-geoip: Depends: nginx (= 1.14.0-1~jessie)

Nginx-module-image-filter: Depends: nginx (= 1.14.0-1~jessie)

Nginx-module-njs: Depends: nginx (= 1.14.0-1~jessie)

Nginx-module-perl: Depends: nginx (= 1.14.0-1~jessie)

Nginx-module-xslt: Depends: nginx (= 1.14.0-1~jessie)

E: Unable to correct problems, you have held broken packages.

The command'/ bin/sh-c apt-key adv-- keyserver hkp://pgp.mit.edu:80-- recv-keys 573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62 & & echo "deb http://nginx.org/packages/debian/ jessie nginx" > > / etc/apt/sources.list & & apt-get update & & apt-get install--no-install-recommends-- no-install-suggests-y ca-certificates nginx=$ {NGINX_VERSION} nginx-module-xslt nginx-module-geoip nginx-module-image-filter nginx-module- Perl nginx-module-njs gettext-base & & rm-rf / var/lib/apt/lists/*' returned a non-zero code: 100

[root@huixuan nginx] #

After the creation is completed, we can find the image we just created in the local image list.

Method one I did not create it successfully.

Method 2. Docker pull nginx

Find the nginx image on Docker Hub

[root@huixuan nginx] # docker search nginx

Here we pull the official image.

After waiting for the download to complete, we can look up the image whose REPOSITORY is nginx in the list of local images.

[root@huixuan nginx] # docker pull nginx

Using default tag: latest

Trying to pull repository docker.io/library/nginx...

Latest: Pulling from docker.io/library/nginx

F2aa67a397c4: Pull complete

3c091c23e29d: Pull complete

4a99993b8636: Pull complete

Digest: sha256:0edf702c890e9518b95b2da01286509cd437eb994b8d22460e40d72f6b79be49

Status: Downloaded newer image for docker.io/nginx:latest

[root@huixuan nginx] #

Use nginx mirroring

Run the container

[root@huixuan nginx] # docker run-p 80:80-- name mynginx-v $PWD/www:/www-v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf-v $PWD/logs:/wwwlogs-d nginx

C782a8c09f261929ef26fe5cbcebc85dd9dda76c97475878f77b8a2ad3faa175

/ usr/bin/docker-current: Error response from daemon: oci runtime error: container_linux.go:247: starting container process caused "process_linux.go:364: container init caused\" rootfs_linux.go:54: mounting\\ "/ root/nginx/conf/nginx.conf\" to rootfs\\ "/ var/lib/docker/overlay2/a573557a07d294822e22c1a260a9531ba8e77a53a392d16dc9bdddfaf7147398/merged\\" at\ "/ var/lib/docker/overlay2/a573557a07d294822e22c1a260a9531ba8e77a53a392d16dc9bdddfaf7147398/merged/etc/nginx/nginx.conf\\ \ "caused\" not a directory\ "\"

Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type.

[root@huixuan nginx] #

Start with the following command

[root@huixuan nginx] # docker run-p 80:80-- name mynginx1111-d nginx

E5f669143490eb6dd86816da584c375d17f9ca137b8d061e9251536f7172233d

[root@huixuan nginx] #

Command description:

-p 80:80: map port 80 of the container to port 80 of the host

-- name mynginx: name the container mynginx

-v $PWD/www:/www: Mount the www under the current directory in the host to the container's / www

-v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf: Mount the nginx.conf under the current directory in the host to the container's / etc/nginx/nginx.conf

-v $PWD/logs:/wwwlogs: Mount the logs under the current directory in the host to the container's / wwwlogs

Check the container startup status

[root@huixuan nginx] # docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

E5f669143490 nginx "nginx-g'daemon..." 37 seconds ago Up 36 seconds 0.0.0.0 daemon 80-> 80/tcp mynginx1111

[root@huixuan nginx] #

Access through a browser

What is the method of installing Nginx on Docker is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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