Luego de instalar Docker en Debian, el siguiente paso en probar y entender su funcionamiento básico. En este artículo se demuestra cómo cargar una imagen de Docker getting-started y sus comandos básicos.

Prueba de funcionamiento con la aplicación getting-started

Instalar la app getting-started de Docker:

emi@vaio:~$ mkdir ~/develop && cd ~/develop
emi@vaio:~/develop$ git clone https://github.com/docker/getting-started.git
emi@vaio:~/develop$ cd getting-started/app/

Esta imagen cuenta con una app de prueba que escucha peticiones en el puerto 3000.

Crear el archivo Dockerfile con la definición de la imagen:

emi@vaio:~/develop/getting-started/app$ nano Dockerfile
# syntax=docker/dockerfile:1
FROM node:12-alpine
RUN apk add --no-cache python g++ make
WORKDIR /app
COPY . .
RUN yarn install --production
CMD ["node", "src/index.js"]

Crear una nueva imagen:

emi@vaio:~/develop/getting-started/app$ docker build -t getting-started .

Ejemplo:

emi@vaio:~/develop/getting-started/app$ docker build -t getting-started .
Sending build context to Docker daemon  4.659MB
Step 1/6 : FROM node:12-alpine
12-alpine: Pulling from library/node
ddad3d7c1e96: Pull complete 
3a8370f05d5d: Pull complete 
71a8563b7fea: Pull complete 
119c7e14957d: Pull complete 
Digest: sha256:9923c9efb13cf7535f67e49b03010f0977a800068e4c8e0e2c93433a6bfa1e77
Status: Downloaded newer image for node:12-alpine
 ---> deeae3752431
Step 2/6 : RUN apk add --no-cache python g++ make
 ---> Running in 1a20b8076351
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz
(1/21) Installing binutils (2.33.1-r1)
(2/21) Installing gmp (6.1.2-r1)
(3/21) Installing isl (0.18-r0)
(4/21) Installing libgomp (9.3.0-r0)
(5/21) Installing libatomic (9.3.0-r0)
(6/21) Installing mpfr4 (4.0.2-r1)
(7/21) Installing mpc1 (1.1.0-r1)
(8/21) Installing gcc (9.3.0-r0)
(9/21) Installing musl-dev (1.1.24-r3)
(10/21) Installing libc-dev (0.7.2-r0)
(11/21) Installing g++ (9.3.0-r0)
(12/21) Installing make (4.2.1-r2)
(13/21) Installing libbz2 (1.0.8-r1)
(14/21) Installing expat (2.2.9-r1)
(15/21) Installing libffi (3.2.1-r6)
(16/21) Installing gdbm (1.13-r1)
(17/21) Installing ncurses-terminfo-base (6.1_p20200118-r4)
(18/21) Installing ncurses-libs (6.1_p20200118-r4)
(19/21) Installing readline (8.0.1-r0)
(20/21) Installing sqlite-libs (3.30.1-r2)
(21/21) Installing python2 (2.7.18-r0)
Executing busybox-1.31.1-r10.trigger
OK: 212 MiB in 37 packages
Removing intermediate container 1a20b8076351
 ---> a777ad1917ee
Step 3/6 : WORKDIR /app
 ---> Running in f5e7a9ebc8f6
Removing intermediate container f5e7a9ebc8f6
 ---> 2065952d1f00
Step 4/6 : COPY . .
 ---> b87a9932c7f3
Step 5/6 : RUN yarn install --production
 ---> Running in aed028959307
yarn install v1.22.5
[1/4] Resolving packages...
[2/4] Fetching packages...
info fsevents@1.2.9: The platform "linux" is incompatible with this module.
info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
Done in 13.96s.
Removing intermediate container aed028959307
 ---> 2874c82dbaef
Step 6/6 : CMD ["node", "src/index.js"]
 ---> Running in ca7260481d53
Removing intermediate container ca7260481d53
 ---> 664c1507c767
Successfully built 664c1507c767
Successfully tagged getting-started:latest

Listar las imágenes:

emi@vaio:~/develop/getting-started/app$ docker image ls
REPOSITORY        TAG         IMAGE ID       CREATED          SIZE
getting-started   latest      664c1507c767   21 minutes ago   383MB
node              12-alpine   deeae3752431   13 days ago      88.9MB
hello-world       latest      d1165f221234   7 weeks ago      13.3kB

Lanzar la imagen:

emi@vaio:~/develop/getting-started/app$ docker run -dp 3000:3000 getting-started
3e7cf2fdcd643c53767aa75a1cbcb21cc6f6db765935f367e75fd0028ea7db2b

Listar los contenedores en ejecución:

emi@vaio:~/develop/getting-started/app$ docker container ls
CONTAINER ID   IMAGE             COMMAND                  CREATED              STATUS              PORTS                                       NAMES
3e7cf2fdcd64   getting-started   "docker-entrypoint.s…"   About a minute ago   Up About a minute   0.0.0.0:3000->3000/tcp, :::3000->3000/tcp   practical_sutherland

Acceder a la app con curl:

emi@vaio:~/develop/getting-started/app$ curl http://localhost:3000

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, maximum-scale=1.0, user-scalable=0" />
    <link rel="stylesheet" href="/css/bootstrap.min.css" crossorigin="anonymous" />
    <link rel="stylesheet" href="/css/font-awesome/all.min.css" crossorigin="anonymous" />
    <link href="https://fonts.googleapis.com/css?family=Lato&display=swap" rel="stylesheet" />
    <link rel="stylesheet" href="/css/styles.css" />
    <title>Todo App</title>
</head>
<body>
    <div id="root"></div>
    <script src="/js/react.production.min.js"></script>
    <script src="/js/react-dom.production.min.js"></script>
    <script src="/js/react-bootstrap.js"></script>
    <script src="/js/babel.min.js"></script>
    <script type="text/babel" src="/js/app.js"></script>
</body>
</html>

Comandos básicos

Detener un contenedor:

emi@vaio:~/develop/getting-started/app$ docker container stop 3e7cf2fdcd64
3e7cf2fdcd64

Listar todos los contenedores (incluyendo detenidos):

emi@vaio:~/develop/getting-started/app$ docker container ls -a
CONTAINER ID   IMAGE             COMMAND                  CREATED          STATUS                      PORTS     NAMES
3e7cf2fdcd64   getting-started   "docker-entrypoint.s…"   24 seconds ago   Exited (0) 11 seconds ago             busy_newton
ddd4aa782f14   hello-world       "/hello"                 35 minutes ago   Exited (0) 35 minutes ago             exciting_noyce

Eliminar un contenedor:

emi@vaio:~/develop/getting-started/app$ docker container rm 3e7cf2fdcd64
3e7cf2fdcd64

Referencias

Compartí este artículo