# https://docs.docker.com/engine/reference/commandline/container/
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b650456536c7 busybox:latest top 54 minutes ago Up 54 minutes 0.0.0.0:1234->9876/tcp, 0.0.0.0:4321->7890/tcp test
docker container ls -l
docker container ls --latest
docker container ls -a
docker container ls --all
docker kill my_container
# docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
docker exec -it my_container sh -c "echo a && echo b"
docker compose rm # Removes stopped service containers
docker compose up
docker compose up -d / docker compose up --detach
___________________________________
docker start [OPTIONS] CONTAINER [CONTAINER...]
docker start my_container
docker stop [OPTIONS] CONTAINER [CONTAINER...]
docker stop my_container
# Remove one or more images, docker rmi
docker rmi [OPTIONS] IMAGE [IMAGE...]
--force, -f
--no-prune
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
test1 latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB)
test latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB)
test2 latest fd484f19954f 23 seconds ago 7 B (virtual 4.964 MB)
docker rmi fd484f19954f
docker rmi test1:latest
#Untagged: test1:latest
docker port test
# 7890/tcp -> 0.0.0.0:4321
# 9876/tcp -> 0.0.0.0:1234
docker port test 7890/tcp
# 0.0.0.0:4321
# docker tag
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
docker tag 0e5574283393 fedora/httpd:version1.0 #by ID
docker tag httpd fedora/httpd:version1.0 #by NAME
# docker rename
docker rename CONTAINER NEW_NAME
docker rename my_container my_new_container
# docker volume
docker volume create [OPTIONS] [VOLUME]
--name
--driver, -d
--opt, -o
docker volume create hello
docker run -d -v hello:/world busybox ls /world
#
docker init
# -it
docker exec -it db psql -U postgres
# compose up
docker compose up --build
# Develop App and Setting
docker volume create mongodb
docker volume create mongodb_config
docker network create mongodb
docker run -it --rm -d -v mongodb:/data/db \
-v mongodb_config:/data/configdb -p 27017:27017 \
--network mongodb \
--name mongodb \
mongo
# docker build --tag, -t
docker build --tag dotnet-docker .
docker build -t dotnet-docker
# docker images
docker images
# docker tag
docker tag dotnet-docker:latest dotnet-docker:v1.0.0
# docker rmi / delete
docker rmi dotnet-docker:v1.0.0
# docker run
docker run dotnet-docker
# --publish, -p // [host port]:[container port]
docker run --publish 5000:80 dotnet-docker
# --detach, -d
docker run -d -p 5000:80 dotnet-docker
# --name
docker run -d -p 5000:80 --name dotnet-app dotnet-docker
https://docs.docker.com/storage/volumes/
# --volume, -v
docker run --rm -d -v postgres-data:/var/lib/postgresql/data \
--network postgres-net \
--name db \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=example \
postgres
# example
docker run \
--rm -d \
--network postgres-net \
--name dotnet-app \
-p 5000:80 \
dotnet-docker
docker run \
--rm -d \
--network postgres-net \
--name db-admin \
-p 8080:8080 \
adminer
# Dockerfile
-------------------
# syntax=docker/dockerfile:1
FROM mcr.microsoft.com/dotnet/sdk:7.0 as build-env
WORKDIR /src
COPY src/*.csproj .
RUN dotnet restore
COPY src .
RUN dotnet publish -c Release -o /publish
FROM mcr.microsoft.com/dotnet/aspnet:7.0 as runtime
WORKDIR /publish
COPY --from=build-env /publish .
EXPOSE 80
ENTRYPOINT ["dotnet", "myWebApp.dll"]
--------------------
# .dockerignore
**/bin/
**/obj/
# Dockerfile
FROM python:3
WORKDIR /usr/src/app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD [ "python", "./app.py" ]
docker build -t my-python-app .
docker run -it --rm --name my-running-app my-python-app
# For many simple, single file projects, you may find it inconvenient to write a complete Dockerfile.
# In such cases, you can run a Python script by using the Python Docker image directly:
docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp python:3 python your-daemon-or-script.py
______________________________________
for CMD
docker run -d -it --name python311dev -v %cd%:/usr/src -w /usr/src mcr.microsoft.com/devcontainers/python
for PowerShell
docker run -d -it --name python311dev -v ${PWD}:/usr/src -w /usr/src mcr.microsoft.com/devcontainers/python
for Linux
docker run -d -it --name python311dev -v $(PWD):/usr/src -w /usr/src mcr.microsoft.com/devcontainers/python
# 1회 실행할 때
docker run -rm -it
# asp.net 실행 ("url에 따옴표 없어도 실행됨)
dotnet run --urls http://localhost:5000
** vscode에서 Dev Containter(Docker) - images에서 "Run Interactive" 메뉴를 사용하면 바로 테스트 해보기 좋음
_
반응형