Downloads the image and run it.
docker run ubuntu
Run in background
docker run -d ubuntu
Downloads the image, but does not the run it.
docker pull ubuntu
List the images downloaded
docker images
List the images the be running.
docker ps
docker ps -a
Start container with data previous.
docker start ID
Show logs container.
docker logs ID
docker logs ID -f
Execute command inside a container, -it session interactive and emulate terminal .
docker exec -it ID sh
or
docker exec -it ID /bin/bash
Stop container
docker stop ID
Delete Container
docker rm ID
Delete Container with Volumes
docker rm ID -fv
List Volumes
docker volume ls
Delete all volumes
docker volume prune
Generate Docker File
-------------------------------------------------------------------------------------
FROM
WORKDIR /app
COPY . .
RUN npm install
CMD ["node", "/app/src/index.js"]
-------------------------------------------------------------------------------------
Build image.
docker build -t node-myapp .
Run image builded.
docker run -pd 3000:3000 node-myapp
Run image share data with container.
docker run -pd 3000:3000 -v /localdir/app/src:/app/src node-myapp
Save changes in the image.
docker build -t node-myapp:v2 .
Share network between both containers.
docker run -dp 3000:3000 --network myapp-net -e MYSQL_HOST=mysql -e MYSQL_USER=root -e MYSQL_PASSWORD=secret -e MYSQL_DB=myapp-db node-myapp:v2
docker run -d --network myapp-net --network-alias mysql -v todo-mysql-data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=secret -e MYSQL_DATABASE=myapp-db mysql:5.7
Docker Compose.
-----------------------------------------------------------
version: "3.7"
services: |
|
#docker run -dp 3000:3000 --network myapp-net -e MYSQL_HOST=mysql -e MYSQL_USER=root -e MYSQL_PASSWORD=secret -e MYSQL_DB=myapp-db node-myapp:v2 |
|
app: |
image: usernamedocker/node-myapp:v2 |
ports: |
- 3000:3000 |
environment: |
MYSQL_HOST: mysql |
MYSQL_USER: root |
MYSQL_PASSWORD: secret |
MYSQL_DB: myapp-db |
|
# docker run -d --network myapp-net --network-alias mysql -v todo-mysql-data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=secret -e MYSQL_DATABASE=myapp-db mysql:5.7 |
|
mysql: |
image: mysql:5.7 |
volumes: |
- ./todo-mysql-data:/var/lib/mysql |
environment: |
MYSQL_ROOT_PASSWORD: secret |
version: "3.7" |
-----------------------------------------------------------
Build images and run background.
docker-compose up -d
0 Comments