Solution to the problem that docker nginx cannot be accessed after running

Solution to the problem that docker nginx cannot be accessed after running

## 1

I'm learning docker deployment recently, and I initially planned to dockerize nginx.

Refer to the official Docker image description for custom configuration

After copying the official nginx.conf, I modified and added some customizations, mainly blocking the default.conf and the include folder sites-available

# include /etc/nginx/conf.d/.conf;
include /etc/nginx/sites-available/;

Official original configuration

user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
  worker_connections 1024;
}


http {
  include /etc/nginx/mime.types;
  default_type application/octet-stream;

  log_format main '$remote_addr - $remote_user [$time_local] "$request" '
           '$status $body_bytes_sent "$http_referer" '
           '"$http_user_agent" "$http_x_forwarded_for"';

  access_log /var/log/nginx/access.log main;

  sendfile on;
  #tcp_nopush on;

  keepalive_timeout 65;

  #gzip on;

  include /etc/nginx/conf.d/*.conf;
}

Create a new docker-compose.yml file and simply specify images, names, ports, and mount local files instead of defaults.

version: '3'
services:
 nginx-proxy:
  image: nginx
  container_name: nginx
  ports:
   -8081:80
  volumes:
   - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro

## 2

After running docker-compose up, it keeps getting stuck at attaching to nginx, and the browser cannot access the port address

Starting nginx ... done
Attaching to nginx

I don't know where the problem is. After searching for information, I found that I can use the tty parameter for debugging.

Modify docker-compose.yml and add a configuration tty:true.

docker exec -it nginx /bin/bash

I found that after I deleted the default default.conf and did not add any other configuration files, the previous sites-available folder was empty.

## 3

I dug myself up, add

-./nginx/sites-available:/etc/nginx/sites-available:ro

And add a configuration file in sites-available.

/etc/nginx/sites-available# ls
default.conf

After running, access to the port address is finally normal

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Detailed graphic tutorial on how to enable remote secure access with Docker
  • Solution to the problem of not being able to access the home page when adding a tomcat container to Docker
  • How to directly access the docker for windows container intranet through an independent IP
  • A troubleshooting experience of centos Docker bridge mode unable to access the host Redis service
  • Detailed explanation of using Docker to build externally accessible MySQL
  • Detailed explanation of how to solve the problem that the docker container cannot access the host machine through IP
  • How to access the local machine (host machine) in Docker
  • How to use Docker container to access host network
  • Method for accessing independent IP in Docker container
  • Three ways to communicate between Docker containers

<<:  How to create a child process in nodejs

>>:  Linux platform mysql enable remote login

Recommend

Analyzing ab performance test results under Apache

I have always used Loadrunner to do performance t...

Vue implements Modal component based on Teleport

Table of contents 1. Get to know Teleport 2. Basi...

JavaScript to achieve a simple message board case

Use Javascript to implement a message board examp...

Vue implements multiple selections in the bottom pop-up window

This article example shares the specific code of ...

Implementation of k8s node rejoining the master cluster

1. Delete node Execute kubectl delete node node01...

Multiple ways to calculate age by birthday in MySQL

I didn't use MySQL very often before, and I w...

Detailed explanation of MySQL cumulative calculation implementation method

Table of contents Preface Demand Analysis Mysql u...

Implementation of MySQL scheduled backup script under Windows

On a Windows server, if you want to back up datab...

In-depth analysis of the Identifier Case Sensitivity problem in MySQL

In MySQL, you may encounter the problem of case s...

jQuery implements employee management registration page

This article example shares the specific code of ...

Problems encountered in using MySQL

Here are some problems encountered in the use of ...