---
# System prepended metadata

title: '[1] Docker for newbie'
tags: [Docker]

---

---
tags: Docker
---
# [1] Docker for newbie

What is Docker?

Docker is an open-source platform for building, deploying, and managing containerized applications.

- image
- container 

---

dockerhub : a place of storing images

## Category

### 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**.

```
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 framework:
```
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)

```
docker exec (options) (container name) (command)
```

### 4. Docker commit

>The purpose is to commit a container be a version.

```
docker commit (container ID) (image name)
```

Ex:
```
docker commit chieh chiehpower:0.1
```

### 5. Docker tag 

>The purpose is to change the image name.


### 6. Docker cp

>The purpose is to copy the files to your destination.

```
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
```


## Slide

- [Slide](https://docs.google.com/presentation/d/e/2PACX-1vQ1HcRWegNDMkDKT0hqQPLlglmx3CGf_upObi7jt7QuCvSELfJrZpgT1mR57Q7IC9efc766AMk5Mc-0/pub?start=false&loop=false&delayms=3000)


### how to push to dockerhub and docker tag rule