Skip to content

Commit 0e8743a

Browse files
committed
revisado módulo III hasta la demo de IntelliJ
1 parent 9e60d4b commit 0e8743a

8 files changed

Lines changed: 31 additions & 114 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.vscode/
2+
.DS_Store

.vscode/launch.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

.vscode/tasks.json

Lines changed: 0 additions & 39 deletions
This file was deleted.

01-contenedores/.DS_Store

-6 KB
Binary file not shown.
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
11
# ---- Base Node ----
2-
FROM alpine:3.12 AS base
3-
# install node
4-
RUN apk add --no-cache nodejs-current nodejs-npm
2+
FROM node:12.18-alpine AS base
3+
#Add some labels
4+
LABEL maintainer="Gisela Torres"
55
# set working directory
66
WORKDIR /app
77

88
#
99
# ---- Dependencies ----
1010
FROM base AS dependencies
1111
# Copy project file
12-
COPY package*.json ./
13-
# Install ALL node_modules, including 'devDependencies'
14-
RUN npm install
12+
COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "./"]
1513

1614
#
1715
# ---- Test ----
1816
# run linters, setup and tests
1917
FROM dependencies AS test
18+
# Install ALL node_modules, including 'devDependencies'
19+
RUN npm install --silent
2020
COPY . .
2121
RUN npm run test
2222

2323

2424
#
2525
# ---- Release ----
2626
FROM base AS release
27+
#Add environment variables
28+
ENV NODE_ENV production
2729
# copy production node_modules
2830
COPY --from=dependencies /app/package.json ./
2931
#Install app dependencies
30-
RUN npm install --only=production
32+
RUN npm install --silent --production && mv node_modules ../
3133
# copy app sources
3234
COPY . .
3335
# expose port and define CMD
3436
EXPOSE 3000
3537
#specify what command it'll execute when you create a container
36-
CMD npm run start
38+
CMD ["npm", "start"]
Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
1-
FROM alpine:3.12 AS base
2-
# install node
3-
RUN apk add --no-cache nodejs-current nodejs-npm
4-
# set working directory
5-
WORKDIR /app
6-
# copy project file
7-
COPY package*.json ./
8-
# install ALL node_modules, including 'devDependencies'
1+
FROM node:12.18-alpine
2+
LABEL maintainer="Gisela Torres"
3+
# ENV NODE_ENV production
4+
WORKDIR /usr/src/app
5+
COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "./"]
96
RUN npm install
10-
#copying the rest of the files
117
COPY . .
12-
#Execute eslint
13-
RUN npm run test
14-
#What port you'll use
8+
RUN npm run test
159
EXPOSE 3000
16-
#specify what command it'll execute when you create a container
17-
CMD npm run start
10+
CMD ["npm", "start"]

01-contenedores/contenedores-iii/contenedores-iii.sh

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Parte 3: contenerización de aplicaciones #
22

33
#Mi primera applicación a contenerizar > Node.js
4+
#Para esta demo usaremos VS Code.
5+
https://code.visualstudio.com/docs/containers/overview
46
cd 01-contenedores/contenedores-iii/hello-world
57

68
#Ejecutar la app sin contenerizar
@@ -56,48 +58,24 @@ docker run -p 4000:3000 hello-world
5658
#Si vuelves a generar tu imagen, después de que arregles los errores que reporta eslint, comprobarás que ha engordado
5759
docker images
5860

59-
#Añadir una nueva etiqueta a tu nueva imagen
60-
docker image tag hello-world 0gis0/hello-world:latest
61-
docker images #El image ID es el mismo para ambas etiquetas porque apuntan a la misma imagen
62-
63-
#Publicar tu nueva imagen en Docker Hub
64-
docker push 0gis0/hello-world:latest
65-
66-
#Si accedes a tu cuenta en Docker Hub verás tu nueva imagen, la cual acaba de ser publicada
67-
https://hub.docker.com/
68-
69-
#Elimina la imagen de local
70-
docker rm 5bfeba90ec4d --force
71-
docker rmi -f hello-world 0gis0/hello-world
72-
73-
#Ejecutar un nuevo contenedor usando mi nueva imagen en Docker Hub
74-
docker run -p 4000:3000 0gis0/hello-world
75-
7661
### Multi-stage Builds ###
77-
#Ejemplo sin multi-stage
78-
docker build hello-world -t no-multi-stage -f Dockerfile.no.multistages --no-cache
79-
docker run -p 4000:3000 no-multi-stage
80-
8162
#Con multi-stage lo que se hace es utilizar múltiples FROM dentro del mismo Dockerfile.
8263
#Cada FROM utiliza una imagen base diferente y cada una inicia un nuevo stage.
8364
#El último FROM produce la imagen final, el resto solo serán intermediarios.
8465
#Puedes copiar archivos de un stage a otro, dejando atrás todo lo que no quieres para la imagen final.
8566
#La idea es simple: crea imagenes adicionales con las herramientas que necesitas (compiladores, linters, herramientas de testing, etc.) pero que no son necesarias para producción
8667
#El objetivo final es tener una imagen productiva lo más slim posible y segura.
8768
#Mismo ejemplo con multi-stages
88-
docker build hello-world -t multi-stage -f Dockerfile.multistages --no-cache
69+
docker build hello-world -t multi-stage -f Dockerfile.multistages
8970
docker run -p 5000:3000 multi-stage
9071

9172
docker images
9273

93-
### Squash de una imagen ###
94-
docker inspect no-multi-stage
95-
docker build hello-world -t image-squashed -f Dockerfile.no.multistages --no-cache --squash
96-
docker images
97-
docker inspect image-squashed
74+
#Si comparas con la versión de la misma aplicación sin multi-stages, la diferencia es notable
75+
docker build hello-world -t no-multi-stage -f Dockerfile.no.multistages --no-cache
9876

9977

100-
#### Ejemplo de contenerización de una aplicación en .NET #####
78+
#### Ejemplo de contenerización de una aplicación en un entorno .NET #####
10179
#Visual Studio 2019
10280
#1. Creación de un nuevo proyecto del tipo ASP.NET Core Web Application
10381
#2. Dejar seleccionado el tipo MVC (Dejar el check de Enable Docker Support deshabilitado)
@@ -106,21 +84,13 @@ docker inspect image-squashed
10684
# Generará un Dockerfile con Multi-stage
10785

10886

109-
110-
#Visual Studio Code
111-
https://code.visualstudio.com/docs/containers/overview
112-
113-
#Demos con la extensión de Docker para Visual Studio Code
114-
# Ejecutar un contenedor desde el explorador de imágenes
115-
# Registros
116-
11787
### Ejemplo de aplicación en Java - IntelliJ IDEA/Eclipse ####
11888
https://www.jetbrains.com/help/idea/running-a-java-app-in-a-container.html
11989

120-
# FROM openjdk:12.0.1
121-
# COPY ./out/production/HelloWorld /tmp
90+
# FROM openjdk:14
91+
# COPY ./out/production/HelloDocker/ /tmp
12292
# WORKDIR /tmp
123-
# ENTRYPOINT ["java", "HelloWorld"]
93+
# ENTRYPOINT ["java","HelloWorld"]
12494

12595
#Ejemplo de aplicación con un contenedor Windows
12696
#Windows Base OS images: https://hub.docker.com/_/microsoft-windows-base-os-images
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
FROM node:12.18-alpine
22
LABEL maintainer="Gisela Torres"
3-
# ENV NODE_ENV production
3+
ENV NODE_ENV production
44
WORKDIR /usr/src/app
55
COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "./"]
6-
RUN npm install
6+
RUN npm install --silent --production && mv node_modules ../
77
COPY . .
8-
RUN npm run test
8+
# RUN npm run test
99
EXPOSE 3000
1010
CMD ["npm", "start"]

0 commit comments

Comments
 (0)