-
<Docker> Nginx Image 생성Flower in my ops/CI\CD 2020. 12. 1. 17:34
Install Nginx
- docker run --privileged -d --name {CONTAINER_NAME} -p 80:80 centos:7 init
- docker ps
- docker exec -it {CONTAINER_NAME} bash
- yum install -y vim
- vim /etc/yum.conf ( ssl 문제 )
sslverify=false
- vim /etc/yum.repos.d/nginx.repo
nginx.org/en/linux_packages.html#RHEL-CentOS
www.nginx.com/resources/wiki/start/topics/tutorials/install/
[nginx] name=nginx repo baseurl=https://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1
- yum install -y nginx
- systemctl enable nginx
- systemctl start nginx
- 방화벽 설정 필요 시
firewall-cmd --permanent --zone=public --add-port={PORT}/tcp firewall-cmd --reload firewall-cmd --list-ports $ vim /etc/nginx/conf.d/default.conf ###--- listen {PORT} ###---
- systemctl restart nginx
더보기flower@docker $ docker run --privileged -d --name flower_centos -p 80:80 centos:7 init 42e696edcebd4ef3c3bf9909d6a8527111373015ff895c71dfc73793fa31081b flower@docker $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 42e696edcebd centos:7 "init" 4 seconds ago Up 3 seconds flower_centos flower@docker $ docker exec -it flower_centos bash [root@42e696edcebd /]$ vim /etc/yum.conf ###--- sslverify=false ###--- [root@42e696edcebd /]$ vim /etc/yum.repos.d/nginx.repo ###--- [nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/7/$basearch/ gpgcheck=0 enabled=1 ###--- [root@42e696edcebd /]$ yum install -y nginx Loaded plugins: fastestmirror, ovl Loading mirror speeds from cached hostfile * base: ftp.kaist.ac.kr * extras: ftp.kaist.ac.kr * updates: ftp.kaist.ac.kr base | 3.6 kB 00:00:00 extras | 2.9 kB 00:00:00 nginx | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 nginx/x86_64/primary_db | 59 kB 00:00:01 Resolving Dependencies --> Running transaction check ---> Package nginx.x86_64 1:1.18.0-2.el7.ngx will be installed --> Processing Dependency: openssl >= 1.0.2 for package: 1:nginx-1.18.0-2.el7.ngx.x86_64 --> Running transaction check ---> Package openssl.x86_64 1:1.0.2k-19.el7 will be installed --> Processing Dependency: make for package: 1:openssl-1.0.2k-19.el7.x86_64 --> Running transaction check ---> Package make.x86_64 1:3.82-24.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================================================================================== Package Arch Version Repository Size ============================================================================================================================================================================================== Installing: nginx x86_64 1:1.18.0-2.el7.ngx nginx 769 k Installing for dependencies: make x86_64 1:3.82-24.el7 base 421 k openssl x86_64 1:1.0.2k-19.el7 base 493 k Transaction Summary ============================================================================================================================================================================================== Install 1 Package (+2 Dependent packages) Total download size: 1.6 M Installed size: 4.6 M Downloading packages: (1/3): openssl-1.0.2k-19.el7.x86_64.rpm | 493 kB 00:00:00 (2/3): make-3.82-24.el7.x86_64.rpm | 421 kB 00:00:00 (3/3): nginx-1.18.0-2.el7.ngx.x86_64.rpm | 769 kB 00:00:04 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total 350 kB/s | 1.6 MB 00:00:04 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : 1:make-3.82-24.el7.x86_64 1/3 Installing : 1:openssl-1.0.2k-19.el7.x86_64 2/3 Installing : 1:nginx-1.18.0-2.el7.ngx.x86_64 3/3 ---------------------------------------------------------------------- Thanks for using nginx! Please find the official documentation for nginx here: * http://nginx.org/en/docs/ Please subscribe to nginx-announce mailing list to get the most important news about nginx: * http://nginx.org/en/support.html Commercial subscriptions for nginx are available on: * http://nginx.com/products/ ---------------------------------------------------------------------- Verifying : 1:nginx-1.18.0-2.el7.ngx.x86_64 1/3 Verifying : 1:openssl-1.0.2k-19.el7.x86_64 2/3 Verifying : 1:make-3.82-24.el7.x86_64 3/3 Installed: nginx.x86_64 1:1.18.0-2.el7.ngx Dependency Installed: make.x86_64 1:3.82-24.el7 openssl.x86_64 1:1.0.2k-19.el7 Complete! [root@42e696edcebd /]$ systemctl enable nginx Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service. [root@42e696edcebd /]$ systemctl start nginx [root@42e696edcebd /]$ curl localhost <!DOCTYPE html> <html> <head> <title>Welcome to nginx!</title> <style> body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } </style> </head> <body> <h1>Welcome to nginx!</h1> <p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p> <p>For online documentation and support please refer to <a href="http://nginx.org/">nginx.org</a>.<br/> Commercial support is available at <a href="http://nginx.com/">nginx.com</a>.</p> <p><em>Thank you for using nginx.</em></p> </body> </html>
Build Image new Nginx
1. Container to Image
- vim index.html (test용으로 작성)
- docker cp index.html {CONTAINER}:/usr/share/nginx/html/index.html
- docker commit {CONTAINER}
- docker images (none & IMAGE_ID 확인)
- docker tag {IMAGE_ID} {NEW_IMAGE}
- docker commit {CONTAINER} {NEW_IMAGE}
- docker stop {CONTAINER}
- docker rm {CONTAINER}
- docker run --privileged -d --name {CONTAINER} -p 80:80 {NEW_IMAGE} init
- docker ps
더보기flower@docker $ vim index.html flower@docker $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 42e696edcebd centos:7 "init" 12 minutes ago Up 12 minutes flower_centos flower@docker $ docker cp index.html flower_centos:/usr/share/nginx/html/index.html flower@docker $ docker exec -it flower_centos bash [root@42e696edcebd /]# curl localhost <html> <head> <title>Nginx</title> </head> <body> <h1>Nginx Server On!</h1> </body> </html> flower@docker $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 42e696edcebd centos:7 "init" 16 minutes ago Up 16 minutes flower_centos flower@docker $ docker commit flower_centos sha256:c49a27368f7f2d7f18d8b86509fb984da65442059f88471c740fa0ddd09ec0c3 flower@docker $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE <none> <none> c49a27368f7f 7 seconds ago 351MB centos 7 8652b9f0cb4c 2 weeks ago 204MB flower@docker $ docker tag c49a27368f7f flower_nginx flower@docker $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE flower_nginx latest c49a27368f7f 2 minutes ago 351MB centos 7 8652b9f0cb4c 2 weeks ago 204MB flower@docker $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 42e696edcebd centos:7 "init" 20 minutes ago Up 20 minutes flower_centos flower@docker $ docker commit flower_centos flower_nginx sha256:b8fbc8a432a5f48aacfa1b1a8a4481fa999ba747ef076bc0eab5d1edba094680 flower@docker $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 42e696edcebd centos:7 "init" 21 minutes ago Up 21 minutes flower_centos flower@docker $ docker stop flower_centos flower_centos flower@docker $ docker rm flower_centos flower_centos flower@docker $ docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES flower@docker $ docker run --privileged -d --name flower_nginx -p 80:80 centos:7 init 921dbe454fe676b583d7843ca4d153d597c983ea13a88d8fd5ccc7742b4f283d flower@docker $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 921dbe454fe6 flower_nginx "init" 2 seconds ago Up 1 second 0.0.0.0:80->80/tcp flower_nginx
2. Dockerfile
더보기FROM centos:7 USER root RUN echo 'sslverify=false' >> /etc/yum.conf RUN touch /etc/yum.repos.d/nginx.repo RUN echo '[nginx]' >> /etc/yum.repos.d/nginx.repo RUN echo 'name=nginx repo' >> /etc/yum.repos.d/nginx.repo RUN echo 'baseurl=https://nginx.org/packages/centos/7/$basearch/' >> /etc/yum.repos.d/nginx.repo RUN echo 'gpgcheck=0' >> /etc/yum.repos.d/nginx.repo RUN echo 'enabled=1' >> /etc/yum.repos.d/nginx.repo RUN yum install -y nginx EXPOSE 80 CMD ["nginx", "-g", "daemon off;"]
'Flower in my ops > CI\CD' 카테고리의 다른 글
<Docker> 명령어 (0) 2020.11.30 <Docker> docker-compose로 한번에 구축 (0) 2020.11.30 <Docker> local(private) registry 구축 (0) 2020.11.25 <CentOS7> Docker ce & Docker compose 설치 (0) 2020.11.25