새 호스트 시스템에 처음으로 Docker 엔진을 설치하기 전에 Docker 리포지토리를 설정해야 합니다. 그런 다음 리포지토리에서 Docker를 설치하고 업데이트할 수 있습니다.
$ sudo apt-get update
$ sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
$ sudo mkdir -p /etc/apt/keyrings
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
$ echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
이미지를 다운받기 이전에, su 권한이 필요합니다
$ sudo su
$ docker pull nginx
$ docker run --name my_nginx -d -p 80:80 -v /home/ubuntu/nginx/nginx.conf:/etc/nginx/nginx.conf nginx
-- name : 실행할 컨테이너의 이름을 지정하여 이후에 이름을 기준으로 제거 가능
$ docker rm my_nginx
-d : 백그라운드로 실행, 백그라운드로 실행하면 현재 명령이 끝나고 백그라운드에서 계속 실행되고 있음.
-p 80:80 : docker가 실행되는 호스트에서 사용할 port : 오른쪽은 Nginx가 사용하는 port (기본 80)
-v : 경로를 설정하여 파일을 마운트 시킨다. 같은 옵션을 여러개 줄수도 있다.
아래와 같이 nginx.conf 파일을 마운트 하여 Nginx 설정값을 변경하거나,
log 폴더를 마운트하면 컨테이너에 직접 접근하지 않아도 Nginx의 log를 볼 수 있음
$ mkdir logs
$ docker run --name my_nginx -d -p 80:80 -v /home/ubuntu/nginx/nginx.conf:/etc/nginx/nginx.conf -v /home/ubuntu/nginx/logs:/var/log/nginx nginx
nginx.conf
# test mount volume
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
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;
}
exec : 외부에서 컨테이너 진입할 때 사용
$ docker exec -it 컨테이너명 /bin/bash
$ exit
안녕하십니까!
게시글과 연관이 없지만 github 서울메이트chat 소스코드를 보다가 궁금한 점이 있어서 댓글 작성합니다.. 혹시 https://github.com/doobyeol/SeoulMateChat에 구현되어있는 채팅기능 DB정보를 알 수 있나요? ERD라도... 감사드립니다... 실례를 무릎쓰고 댓글 답니다... 화이팅입니다.