はじめに
Dockerのチュートリアルです。Dockerfileを作成→Dockerイメージ作成→Docker起動を実施します。
構成
ディレクトリ構成
~/develop/docker/hello_docker $ tree
.
├── Dockerfile
└── init.sh
0 directories, 2 files
Dockerfile作成
dockerfile
FROM alpine:latest
RUN mkdir /work
WORKDIR /work
COPY init.sh .
RUN chmod 755 ./init.sh
CMD ["./init.sh"]
init.sh
#!/bin/ash
echo "Hello, Docker!"
Dockerイメージ作成(build)
ビルド実行
~/develop/docker/hello_docker $ docker build -t hello_docker:latest .
[+] Building 0.2s (10/10) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 36B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/library/alpine:latest 0.0s
=> [1/5] FROM docker.io/library/alpine:latest 0.0s
=> [internal] load build context 0.0s
=> => transferring context: 28B 0.0s
=> CACHED [2/5] RUN mkdir /work 0.0s
=> CACHED [3/5] WORKDIR /work 0.0s
=> CACHED [4/5] COPY init.sh . 0.0s
=> CACHED [5/5] RUN chmod 755 ./init.sh 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:5aef5df4ddba13567f0f2bb33c73c3b34adabc1385d288bd5b29ef551dc57ca2 0.0s
=> => naming to docker.io/library/hello_docker:latest 0.0s
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
イメージ作成を確認
~/develop/docker/hello_docker $ docker images hello_docker
REPOSITORY TAG IMAGE ID CREATED SIZE
hello_docker latest 5aef5df4ddba 3 minutes ago 5.53MB
Docker起動
docker実行
~/develop/docker/hello_docker $ docker container run -it --name hello_docker hello_docker
Hello, Docker!