Docker Cheat Sheet

Jayson Chiang
3 min readNov 22, 2020

--

docker 學了就忘,用來用去就是這幾個指令,還是會忘。

docker run [image]docker create [image] [command]docker start [container id]docker psdocker ps --alldocker stop [container id]docker kill [container id]docker exec -it [container id] [command]docker exec -it [container id] shdocker run -it [image] shdocker system prune
FROM node:alpineWORKDIR '/app'COPY package.json .RUN npm installCOPY . .CMD ["npm", "start"]
docker build -t [docker username]/[image name]:[version]ex: docker build -t jaysonchiang/posts .

Build an image based on the dockerfile in the current directory. Tag it as ‘jaysonchiang/posts’.

docker run [image id or image tag]docker run -p [port]/[port] [image id]

Create and start a container based on the provided image id or tag.

docker run it [image id or image tag][cmd]

Create and start the container, but also override the default command.

docker ps

Print out information about all of the running containers.

docker exec -it [container id][cmd]

Execute the given command in a running container.

docker logs [container id]

Print out logs from the given container

--

--

No responses yet