Docker memorandum

A memorandum when using Docker and docker-compose.

The first site I learned a lot: Introduction to docker and docker-compose-Qiita

docker command

docker ps #List of running containers
docker ps -a #Running+List of finished containers
docker rm [ID] #Delete finished container
docker image ls #At hand(No need to download)Show docker image
docker rmi [Image name] #Delete docker image
docker run [Image name]
docker run --name [Label name] [Container name] #Label nameでコンテナを指定する
docker run -it --run [Container name] #Enter the container and exit to delete the container
docker run -d [Image name] /usr/sbin/httpd -DFOREGROUND #Start the httpd daemon
docker run -d -p 8080:80 [Image name] /usr/sbin/httpd -DFOREGROUND #Start the httpd daemon and skip container 80 to host 8080
docker run -v [Host PATH]:[PATH in container] #Specifying PATH between host and container
docker run --env TERM=xterm256color #Specifying environment variables
docker stop [ID] #Stop container
docker restart [ID] #While running a closed container
docker attach [ID] #Enter a running container
docker exec [ID] [command] #実行中のコンテナにcommandを与える
docker exec -it [ID] /bin/bash #Enter a running container
docker commit [Original image name when stopped] [Image name to make] #Make an image from the original image

When detaching, ctrl + p, q.

When using Dockerfile

Dockerfile


FROM centos:8

RUN yum update -y \
    && yum install httpd -y \
    && echo "hello world from dockerfile" > /var/www/html/index2.html \
    && yum clean all

ADD ./httpd/www/index.html /var/www/html/

EXPOSE 80

ENTRYPOINT ["/usr/sbin/httpd", "-DFOREGROUND"]

And so on

docker build ./ -t [Image name] #Create an image from Dockerfile
docker run -d --rm -p 8080:80 [Image name] #Start the image as a daemon

docker-compose command

In the directory where docker-compose.yml is located

docker-compose up -d #Up
docker-compose down  #Make it stopped

docker-compose.yml


version: "3" #Specify version https://matsuand.github.io/docs.docker.jp.onthefly/compose/compose-file/compose-versioning/

services:
  postgresql:
    build: ./docker/postgresql/ #Where the Dockerfile is located
    ports:
      - 15432:5432 #Port mapping
    environment:
      POSTGRES_USER: hoge #Specifying environment variables
      POSTGRES_PASSWORD: hogehoge
    volumes:
      - ./docker/postgresql/initdb.d:/docker-entrypoint-initdb.d #Volume mapping
      - ./docker/postgresql/data:/var/lib/postgresql/data

  service1:
    image: service1 #Directly specify the image
    ports:
      - 8888:8888
    volumes:
      - ./app:/usr/src/server

Reference site: I tried to explain how to write docker-compose.yml --Qiita

Recommended Posts

Docker memorandum
Docker memorandum
Technical memorandum (Docker)
Memorandum docker command
Docker command memorandum
Docker Machine (personal memorandum)
memorandum
memorandum
Docker network (personal memorandum)
docker
docker memo
kubernetes + docker
spring × docker
About Docker
MyBatis memorandum
Docker Intellij
Java memorandum
Docker basics
Rails memorandum
Error memorandum
Jaba Jaba Memorandum
Docker installation
JavaFx memorandum
About Docker
JAVA memorandum
JUnit memorandum
Gradle Memorandum
Understand Docker
thymeleaf memorandum
Launch docker container on EC2 (personal memorandum)
docker tutorial (memo)
What is Docker?
Docker basic summary
Docker + Laravel + Codeception
Liberty on Docker
Docker operation memo
[wip] Docker notes
Log Level Memorandum
Apache FreeMarker memorandum
Building a CICD pipeline using Docker (personal memorandum)
Java memorandum (list)
What is Docker
Screen transition memorandum
docker volume checked
Docker command memo
docker basic command
[Ruby] Method memorandum
Data management using volume in Docker (personal memorandum)
Rails tutorial memorandum 2
[Memo] docker summary
Docker study notes
Docker command summary
Quick docker / nginx
Docker in LXD
Rails Docker ~ Part 1 ~
Rails Docker ~ Part 2 ~
heroku: docker: deploy
/ n \ n docker java
What is Docker
Java study memorandum
Spring Boot Memorandum