# Criação da Imagem e Envio para o Docker Hub

```bash
$ docker container ls -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
$ docker image ls -a
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
$ docker network ls
NETWORK ID     NAME      DRIVER    SCOPE
131df83cc78a   bridge    bridge    local
73f2d51a39de   host      host      local
9198ba9fc6fd   none      null      local
```

Clonar o repositório:

```bash
$ cd /tmp
/tmp$ git clone https://github.com/marcelobarbieri/devops-kube-news.git
Cloning into 'devops-kube-news'...
remote: Enumerating objects: 67, done.
remote: Total 67 (delta 0), reused 0 (delta 0), pack-reused 67 (from 1)
Receiving objects: 100% (67/67), 1.92 MiB | 8.09 MiB/s, done.
Resolving deltas: 100% (10/10), done.
/tmp$ ls
devops-kube-news  
/tmp$ cd devops-kube-news/
/tmp/devops-kube-news$ ls
README.md  popula-dados.http  src
/tmp/devops-kube-news$ code .
```

Criação do Docker Ignore:

```bash
/tmp/devops-kube-news$ cd src/
/tmp/devops-kube-news/src$ touch .dockerignore
/tmp/devops-kube-news/src$ vim .dockerignore
/tmp/devops-kube-news/src$ cat .dockerignore
# Dependency directories
node_modules/
```

Criação do Dockerfile:

```bash
/tmp/devops-kube-news/src$ touch Dockerfile
/tmp/devops-kube-news/src$ vim Dockerfile
/tmp/devops-kube-news/src$ cat Dockerfile
```

```docker
FROM node:20.10.0-alpine3.18
WORKDIR /app
COPY package*.json .
RUN npm install
COPY . .
EXPOSE 8080
CMD ["node","server.js"]
```

Construção da imagem no Docker Registry:

```bash
/tmp/devops-kube-news/src$ docker build \ 
    -t marcelodpbarbieri/kube-news:v1 \
    -f Dockerfile \
    .
[+] Building 1.4s (10/10) FINISHED                docker:default
 => [internal] load build definition from Dockerfile        0.0s
 => => transferring dockerfile: 163B                        0.0s
 => [internal] load metadata for docker.io/library/node:20  1.3s
 => [internal] load .dockerignore                           0.0s
 => => transferring context: 79B                            0.0s
 => [internal] load build context                           0.0s
 => => transferring context: 862B                           0.0s
 => [1/5] FROM docker.io/library/node:20.10.0-alpine3.18@s  0.0s
 => CACHED [2/5] WORKDIR /app                               0.0s
 => CACHED [3/5] COPY package*.json .                       0.0s
 => CACHED [4/5] RUN npm install                            0.0s
 => CACHED [5/5] COPY . .                                   0.0s
 => exporting to image                                      0.0s
 => => exporting layers                                     0.0s
 => => writing image sha256:522e75b2d4b547f5d1649c6ad9ceaf  0.0s
 => => naming to docker.io/marcelodpbarbieri/kube-news:v1   0.0s
```

```bash
/tmp/devops-kube-news/src$ docker image ls -a
REPOSITORY                    TAG       IMAGE ID       CREATED         SIZE
marcelodpbarbieri/kube-news   v1        522e75b2d4b5   2 minutes ago   169MB

/tmp/devops-kube-news/src$ docker login
Authenticating with existing credentials...
WARNING! Your password will be stored unencrypted in /home/marcelo/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credential-stores

Login Succeeded

/tmp/devops-kube-news/src$ docker push marcelodpbarbieri/kube-news:v1
The push refers to repository [docker.io/marcelodpbarbieri/kube-news]
10bc55ba8368: Pushed
dca4f09ca245: Pushed
4da4dc0ce65d: Pushed
17e7f2d94c8f: Pushed
e6e17c0d72ff: Mounted from library/node
177e8671cea0: Mounted from library/node
0836ffd7c491: Mounted from library/node
9fe9a137fd00: Mounted from library/node
v1: digest: sha256:520569e61466c33b97ee40b3a254c48835dece1d4b408909582aa482511da3ca size: 1996
```

{% embed url="<https://hub.docker.com/repository/docker/marcelodpbarbieri/kube-news/general>" %}

Subir a imagem `latest` também:

```bash
/tmp/devops-kube-news/src$ docker tag marcelodpbarbieri/kube-news:v1 marcelodpbarbieri/kube-news:latest

$ docker image ls -a
REPOSITORY                    TAG       IMAGE ID       CREATED          SIZE
marcelodpbarbieri/kube-news   latest    522e75b2d4b5   37 minutes ago   169MB
marcelodpbarbieri/kube-news   v1        522e75b2d4b5   37 minutes ago   169MB

$ docker image inspect 522e75b2d4b5 | grep -Ei "kube-news"
            "marcelodpbarbieri/kube-news:latest",
            "marcelodpbarbieri/kube-news:v1"
            
$ docker push marcelodpbarbieri/kube-news:latest
```

<figure><img src="https://2056950903-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7JJDMtYZqFc5W4Gd6mo1%2Fuploads%2FjbcOdFv0sRa7JcyXavby%2Fimage.png?alt=media&#x26;token=6c3a3df1-9ca2-46fe-bf4b-72465687dcf7" alt=""><figcaption></figcaption></figure>
