手順
HTMLを置く
./public/index.html
Hello, World!
nginxのコンフィグファイルを書く
./server.conf
server {
listen 80;
server_name localhost;
server_tokens off;
access_log /root/logs/access.log;
error_log /root/logs/error.log;
location / {
root /root/public;
}
}
Dockerfileを書く
./Dockerfile
FROM nginx
ADD ./server.conf /etc/nginx/conf.d/default.conf
RUN mkdir /root/logs
RUN chmod 755 -R /root
CMD ["nginx", "-g", "daemon off;"]
- default.confを上書きしている
イメージを作る
$ docker build -t simple-nginx .
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
simple-nginx latest 57e237b6b8c0 14 minutes ago 107MB
nginx latest b8efb18f159b 3 weeks ago 107MB
コンテナを作って起動
$ docker run -d -p 80:80 -v $(pwd)/public:/root/public --name your-container-name simple-nginx
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
71dd9f3a6583 simple-nginx "nginx -g 'daemon ..." 3 seconds ago Up 2 seconds 0.0.0.0:80->80/tcp your-container-name
もう見れるはず
bash
$ docker exec -it your-container-name bash
その他
コンテナ操作
$ docker stop your-container-name
$ docker start your-container-name
$ docker rm your-container-name
イメージを消す
$ docker rmi simple-nginx