Docker Command

sudo docker info
sudo docker version
sudo docker container stats #Display a live stream of container(s) resource usage statistics
sudo docker pull ubuntu:20.04
sudo docker run ubuntu
sudo docker images
sudo docker image ls #與上一行結果相同
sudo docker container ls -a
sudo docker ps -a #list all container
sudo docker start <CONTAINER ID> #it will up on background
sudo docker stop <CONTAINER ID>
sudo docker rm <CONTAINER ID> #remove container
sudo docker rmi <image ID> #remove image, # 刪除 image 前必需將透過該 image 所產生的 container 移除
sudo docker network rm <NETWORK> #刪除Network
sudo docker run -i -t -d ubuntu bash # 產生一個 container 在背景執行
sudo docker inspect -f ‘{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}’ container_name_or_id #get container ip address
docker system prune # factory reset all docker
sudo systemctl restart docker.service
sudo snap restart docker

# 停止所有的 containers
sudo docker stop $(sudo docker ps -a -q)

# 刪除所有的 containers
sudo docker rm $(sudo docker ps -a -q)

# 刪除所有的 images
docker rmi $(docker images -a -q)

_______________________________________________________________________________________________
## get file from container ##
docker cp <containerId>:/file/path/within/container /host/path/target

example:
sudo docker cp es01:/usr/share/elasticsearch/config/elasticsearch.yml ./elasticsearch.yml
_______________________________________________________________________________________________
## put file from localhost ##
docker cp D:\webapi\ssl\certificate.pfx webapi1:c:\inetpub\certificate.pfx #put ssl certificate to container

_______________________________________________________________________________________________
## access docker container ##
sudo docker exec -it <container> bash
sudo docker exec -it c6967650072a bash
_______________________________________________________________________________________________
## running command in docker container ##
sudo docker exec -it <container> /opt/elastalert
sudo docker exec -it webapi systemctl start apache2
sudo docker exec -it webapi systemctl start webapi
_______________________________________________________________________________________________

## resource ##
sudo docker run –name es01 –net elastic -p 9200:9200 -p 9300:9300 -it docker.elastic.co/elasticsearch/elasticsearch:8.4.2 –cpu 2 –memory 2214MB

_______________________________________________________________________________________________
## docker ASP.NET Core ##
#install dotnet sdk on ubuntu
wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb

sudo apt-get update; \
sudo apt-get install -y apt-transport-https && \
sudo apt-get update && \
sudo apt-get install -y dotnet-sdk-3.1

dotnet –info

#install ssl certificate to localhost
sudo cp .aspnet/https/rootCACert.crt /usr/local/share/ca-certificates/extra #import rootca.cert
sudo update-ca-certificates
dotnet dev-certs https –clean –import ./certificate.pfx -p $CREDENTIAL_PLACEHOLDER$

#pull image
sudo docker pull mcr.microsoft.com/dotnet/aspnet:3.1

#create container
sudo docker run -it –rm -p 80:80 -p 443:443 –name webapi mcr.microsoft.com/dotnet/aspnet:3.1

sudo docker run –rm -it -p 80:80 -p 443:443 –name webapi -e ASPNETCORE_URLS=”https://+;http://+” \
-e ASPNETCORE_HTTPS_PORT=443 -e ASPNETCORE_Kestrel__Certificates__Default__Password=”webapi.makalot.com.tw” \
-e ASPNETCORE_Kestrel__Certificates__Default__Path=/https/webapi.makalot.com.tw.pfx -v ${HOME}/aspnet/https/:/https/ mcr.microsoft.com/dotnet/aspnet:3.1
-e, –env list
-v, –volume

發佈日期:
分類: 未分類