04/01/2022   Docker


FROM ubuntu

RUN apt-get update
RUN apt-get install nginx -y

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

- different RUN and CMD
+ RUN run when you build image
+ CMD run when you create container

- CMD ["nginx","-g","daemon off;"]
=> run nginx global, in background

- docker build .
=> build image from Dockerfile in current directory

- docker build . -t nginx-ubuntu:1.0
=> -t (set tag name:version for image)

- docker run -it -d -p 9000:80 nginx-ubuntu bash
=> run container with cmd bash
=> bash is default command, in this case we no need bash bc we want run CMD in Dockerfile
=> docker run -it -p 9000:80 nginx-ubuntu



Bài viết cùng chủ đề