前回
whts is nextのwhat is docker composeとunderstanding image layersを学んだ。yamlファイルを使って複数のdockerをまとめてrun(compose)するのと、imageにlayerを追加する操作を体感した
Writing a DockerFile
A Dockerfiles is a text-based document that's used to a crate a container iamge
imageをつくるための設計図みたいなもんかな
sample
FROM python:3.12
WORDIR /usr/local/app
COPY requirements.txt ./
RUN pip install --nocache-dir -r requirements.txt
COPY src ./src
EXPOSE 5000
RUN useadd app
USER app
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8080"]
一行目から
- FROM : specifies tha base image
- WORDDIR : specifies the working directory or the path in tha image where files be copied and commands will be execited
- COPY : tells builder to copy files from the host and put them into the continer image
- RUN : tells builders to run the specified command
- EXPOSE : sets configuration on the image that indicates a port the image would like to expose
- USER : sets the default user for all subsequent instructions
- CMD ["" , ""]: sets the default command a conteiner using this image will run
tyr it out
デスクトップにtestディレクトリを作成。
中身はDockerfileだけ
FROM node:20-alpine
WORKDIR /usr/local/app
COPY . .
RUN yarn install --production
CMD ["node", "./src/index.js"]
DockerDesktopを起動
→コマンドプロンプトを起動&cd
→docker container build -t myimage .
GUIのimageのところに追加されている。conteinerの作成まではしてないみたい
コマンド実行後もディレクトリにファイルは追加されていない。プロジェクトを作るようなコマンドではないってことかな
Build, tag, and publish an image
Build: the process of building an image based on a Dockerfile
Tagging: the process of giving an image a name, which also detemines where the image can be distributed
tagのformat
例
- docker.io/library/nginx:latest: pulls an image from the docker.io registry, the library namespace, the nginx image repository and the latest tag
- ghcr.io/dockersamples/example-voting-app-vote:pr-311: pulls an image from the GitHub Container Registry, the dockersamples namespace, the example-voting-app-vote iamge repository, and the pr-311 tag
tagを使うと簡単にimage引っ張ってこれますよってこと?よくわからん。try it outは上でやったのとほぼ同じだから省略。
今日は内容すくないけどここまで。