[1] Docker for newbie
- image
- container
dockerhub : a place of storing images
Category
The category is what I organized the most important commands for a beginner that they will use it frequently in the future.
If you can nail it, then you can feel free to use almost 80~90% in Docker.
Action
- docker pull / docker push / docker commit
- docker build : Build an image from a dockerfile. (Advance)
- docker run : Create a container (It can only run once.)
- docker exec : (If you have not created it before, you cannot use it.) Enter a container
- docker start / docker stop : Start a container, and stop a container
- docker rm / docker rmi
- docker cp
Check status
- docker ps (Check the status of containers that is currently running) / docker ps -a (Check all containers)
- docker images (check all images) / docker image ls
- docker info
Command
1. Docker pull
The purpose is to pull the image.
Command:
docker pull (Account):(Tag & version)
Ex:
docker pull ubuntu:20.04
If you do not specify the version you wanna pull, then it will pull the tag of latest version by default.
2. Docker run
The purpose is to create a container from an image.
The main structure:
docker run (options) (image name) (command)
For example:
docker run (options) ubuntu:20.04 bash
Options:
All of options should be put between run
and image name
.
-i -t
(i.g.,-it
) :-i
represents "interactive" and-t
is--tty
.--name
: give a name. (We cannot use the same name.)--rm
: Won't store it after you leave a container.-p
(port) (host):(container) 8080:8080-v
(volume): Mount the folder (host folder absolute path):(container path)-d
: background (The meaning of-d
is "detach")
3. Docker exec (execute)
The purpose is to enter an alive container. (or a running container)
Command:
docker exec (options) (container name) (command)
4. Docker commit
The purpose is to commit a container be a version.
Command:
docker commit (container ID) (image name)
Ex:
docker commit chieh chiehpower:0.1
5. Docker tag
The purpose is to change the image name.
Command:
docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
6. Docker cp
The purpose is to copy the files to your destination.
Command:
docker cp (target) (destination)
(container name):(path)
Ex:
- Copy the
test.py
file from "chieh" container to host (here).
docker cp chieh:/workspace/test.py .
- Copy the
test.py
file from host to the/workspace/test.py
location of "chieh" container.
docker cp test.py chieh:/workspace/test.py