docker-nginx-vhost's People
docker-nginx-vhost's Issues
step2 description
This Docker command runs a detached (-d
) Nginx container named serv-a
. Here's what each part of the command does:
docker run
: This command is used to create and start a Docker container from an image.-it
: This flag stands for "interactive" and "pseudo-TTY." It allows you to interact with the container's shell if you run it in the foreground, but since it's used with-d
here (detached mode), it doesn't have any effect.-d
: This flag tells Docker to run the container in detached mode, meaning it runs in the background and you can continue to use your terminal for other commands.-p 8002:80
: This flag maps port 80 inside the container to port 8002 on your host machine. This means that you can access the Nginx server running inside the container viahttp://localhost:8002
.--name serv-a
: This flag assigns a nameserv-a
to the container, making it easier to reference instead of using its container ID.nginx
: This is the name of the Docker image to use for creating the container. In this case, it's the official Nginx image.
So, when you run this command, Docker will start a detached Nginx container named serv-a
, and you can access the Nginx web server running inside the container via http://localhost:8002
on your host machine.
Docker server 구축
Step 1
- remove all images and containers
$ sudo docker rm (container id)
$ sudo docker rmi (image id)
--------------------------------------------------------------------------------
<results>
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
Step 2
$ docker run -itd -p 8002:80 --name serv-a nginx
$ docker run -itd -p 8003:80 --name serv-a nginx
$ docker run -itd -p 8001:80 --name lb nginx:latest
FYI #2 (comment)
Step 3
- copy local default.conf into (lb) docker container -> lb:/etc/nginx/conf.d
sudo docker cp default.conf lb:/etc/nginx/conf.d
- move local default.config to lb folder and make serv-a, serv-b folder
Step 4
- make index.html file to serv-a serv-b folder & copy to docker container
$sudo docker cp serv-a/index.html serv-a:/usr/share/nginx/html
$sudo docker cp serv-b/index.html serv-b:/usr/share/nginx/html
$tree
.
├── README.md
├── lb
│ └── config
│ └── default.conf
├── serv-a
│ └── index.html
└── serv-b
└── index.html
Step 5
- install ping in container(docker)
$ apt update
$apt install iputils-ping
$apt install telnet
Step 6
$sudo docker network ls
NETWORK ID NAME DRIVER SCOPE
438ec9964d9e bridge bridge local
a5597bd84d88 host host local
ed1a5e80b850 none null local
Dockerfile
1. ~/code/docker-nginx-vhost/serv-a 이 폴더에서 Dockerfile 생성
Dockerfile내부에 입력
FROM nginx
COPY index.html /usr/share/nginx/html
2. Build 하귕
$ sudo docker build -t ng-s-1:0.1.0 . // $ sudo docker build -t ng-s-1:0.1.0 -f serv-a/Docerfile .
3. Run 해보세여 //ps로 확인
$ sudo docker run -d --name s1-1 -p 9001:80 ng-s-1:0.1.0
$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ad3f037e8192 ng-s-1:0.1.0 "/docker-entrypoint.…" 33 seconds ago Up 32 seconds 0.0.0.0:9001->80/tcp, :::9001->80/tcp s1-1
675961f93220 mariadb:latest "docker-entrypoint.s…" 34 minutes ago Up 34 minutes 3306/tcp some-mariadb
02144c114c7b 48d341040c1f "/docker-entrypoint.…" About an hour ago Up About an hour 80/tcp serv-b
2dac2f3ae8d8 d8acd0b76461 "/docker-entrypoint.…" About an hour ago Up About an hour 80/tcp serv-a
4cab17f790a4 nginx:latest "/docker-entrypoint.…" 4 hours ago Up 2 hours 0.0.0.0:8001->80/tcp, :::8001->80/tcp lb
- serv-b 도 동일하게 할께요
중간 출력 확인
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8f3ffddf6bc1 ng-s-2:0.1.0 "/docker-entrypoint.…" 10 seconds ago Up 9 seconds 0.0.0.0:9002->80/tcp, :::9002->80/tcp s1-2
ad3f037e8192 ng-s-1:0.1.0 "/docker-entrypoint.…" 40 minutes ago Up 40 minutes 0.0.0.0:9001->80/tcp, :::9001->80/tcp s1-1
Docker Network Inspect& host abc
$sudo docker network inspect abc
[
{
"Name": "abc",
"Id": "cc45a8b4a7543d4b153c1615ffd860314928765b4861dcbde46c4481f2f54c9b",
"Created": "2024-02-14T12:48:07.239483507+09:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.19.0.0/16",
"Gateway": "172.19.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {},
"Options": {},
"Labels": {}
}
]
Docker Container Log(error) lb
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2024/02/14 02:18:51 [notice] 1#1: using the "epoll" event method
2024/02/14 02:18:51 [notice] 1#1: nginx/1.25.3
2024/02/14 02:18:51 [notice] 1#1: built by gcc 12.2.0 (Debian 12.2.0-14)
2024/02/14 02:18:51 [notice] 1#1: OS: Linux 5.15.133.1-microsoft-standard-WSL2
2024/02/14 02:18:51 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2024/02/14 02:18:51 [notice] 1#1: start worker processes
2024/02/14 02:18:51 [notice] 1#1: start worker process 29
2024/02/14 02:18:51 [notice] 1#1: start worker process 30
2024/02/14 02:18:51 [notice] 1#1: start worker process 31
2024/02/14 02:18:51 [notice] 1#1: start worker process 32
2024/02/14 02:18:51 [notice] 1#1: start worker process 33
2024/02/14 02:18:51 [notice] 1#1: start worker process 34
2024/02/14 02:18:51 [notice] 1#1: start worker process 35
2024/02/14 02:18:51 [notice] 1#1: start worker process 36
172.18.0.1 - - [14/Feb/2024:03:02:52 +0000] "GET / HTTP/1.1" 200 615 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36" "-"
2024/02/14 03:02:52 [error] 29#29: *1 open() "/usr/share/nginx/html/favicon.ico" failed (2: No such file or directory), client: 172.18.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "localhost:8001", referrer: "http://localhost:8001/"
172.18.0.1 - - [14/Feb/2024:03:02:52 +0000] "GET /favicon.ico HTTP/1.1" 404 555 "http://localhost:8001/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36" "-"
172.18.0.1 - - [14/Feb/2024:03:05:24 +0000] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36" "-"
2024/02/14 03:11:14 [notice] 1#1: signal 3 (SIGQUIT) received, shutting down
2024/02/14 03:11:14 [notice] 30#30: gracefully shutting down
2024/02/14 03:11:14 [notice] 29#29: gracefully shutting down
2024/02/14 03:11:14 [notice] 31#31: gracefully shutting down
2024/02/14 03:11:14 [notice] 33#33: gracefully shutting down
2024/02/14 03:11:14 [notice] 32#32: gracefully shutting down
2024/02/14 03:11:14 [notice] 36#36: gracefully shutting down
2024/02/14 03:11:14 [notice] 34#34: gracefully shutting down
2024/02/14 03:11:14 [notice] 30#30: exiting
2024/02/14 03:11:14 [notice] 29#29: exiting
2024/02/14 03:11:14 [notice] 33#33: exiting
2024/02/14 03:11:14 [notice] 31#31: exiting
2024/02/14 03:11:14 [notice] 36#36: exiting
2024/02/14 03:11:14 [notice] 34#34: exiting
2024/02/14 03:11:14 [notice] 32#32: exiting
2024/02/14 03:11:14 [notice] 31#31: exit
2024/02/14 03:11:14 [notice] 29#29: exit
2024/02/14 03:11:14 [notice] 34#34: exit
2024/02/14 03:11:14 [notice] 36#36: exit
2024/02/14 03:11:14 [notice] 30#30: exit
2024/02/14 03:11:14 [notice] 32#32: exit
2024/02/14 03:11:14 [notice] 33#33: exit
2024/02/14 03:11:14 [notice] 35#35: gracefully shutting down
2024/02/14 03:11:14 [notice] 35#35: exiting
2024/02/14 03:11:14 [notice] 35#35: exit
2024/02/14 03:11:14 [notice] 1#1: signal 17 (SIGCHLD) received from 32
2024/02/14 03:11:14 [notice] 1#1: worker process 32 exited with code 0
2024/02/14 03:11:14 [notice] 1#1: signal 29 (SIGIO) received
2024/02/14 03:11:14 [notice] 1#1: signal 17 (SIGCHLD) received from 34
2024/02/14 03:11:14 [notice] 1#1: worker process 34 exited with code 0
2024/02/14 03:11:14 [notice] 1#1: signal 29 (SIGIO) received
2024/02/14 03:11:14 [notice] 1#1: signal 17 (SIGCHLD) received from 36
2024/02/14 03:11:14 [notice] 1#1: worker process 33 exited with code 0
2024/02/14 03:11:14 [notice] 1#1: worker process 36 exited with code 0
2024/02/14 03:11:14 [notice] 1#1: signal 29 (SIGIO) received
2024/02/14 03:11:14 [notice] 1#1: signal 17 (SIGCHLD) received from 30
2024/02/14 03:11:14 [notice] 1#1: worker process 30 exited with code 0
2024/02/14 03:11:14 [notice] 1#1: signal 29 (SIGIO) received
2024/02/14 03:11:14 [notice] 1#1: signal 17 (SIGCHLD) received from 31
2024/02/14 03:11:14 [notice] 1#1: worker process 31 exited with code 0
2024/02/14 03:11:14 [notice] 1#1: worker process 35 exited with code 0
2024/02/14 03:11:14 [notice] 1#1: signal 29 (SIGIO) received
2024/02/14 03:11:14 [notice] 1#1: signal 17 (SIGCHLD) received from 29
2024/02/14 03:11:14 [notice] 1#1: worker process 29 exited with code 0
2024/02/14 03:11:14 [notice] 1#1: exit
/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf differs from the packaged version
/docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2024/02/14 03:11:15 [emerg] 1#1: host not found in upstream "serv-a:80" in /etc/nginx/conf.d/default.conf:2
nginx: [emerg] host not found in upstream "serv-a:80" in /etc/nginx/conf.d/default.conf:2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.