- Install Docker on your PC: "https://www.docker.com/products/docker-desktop/"
-
Download an image:
docker pull [image name] -
Create a container for the new image:
docker create --name [container name] [image] -
Start the container with the container name:
docker start [container name] -
Show and follow logs:
docker logs --follow [container name] -
Check running containers:
docker ps -
Stop a running container:
docker stop [container name] -
Show all containers:
docker ps -a -
Delete a container:
docker rm [container name]
When you run a Docker container, you can expose ports within the container to be accessed from outside the container by mapping those ports to ports on the host (the machine running Docker).
For example, if you have a web application inside a Docker container running on port 8080 within the container, you can map that port to port 8080 on the host. This means that any request that arrives at port 8080 on the host will be redirected to the Docker container, thus allowing access to the web application.
docker create -p [host port]:[container port] [container name] [image]
-
Find the image, if not found, this command creates it:
docker run --name [container name] -p [host port]:[container port] -d [image] -
Initialize the container:
docker start [container name]
```
docker create -p 27017:27017 --name monguito -e MONGO_INITDB_ROOT_USERNAME=nico -e MONGO_INITDB_ROOT_PASSWORD=password mongo
```
A network is used to communicate containers with each other.
-
List networks:
docker network ls -
Create network:
docker network create [network name] -
Create image based on a Dockerfile file
docker build -t [image name:label] [path Dockerfile] -
Create a container linked to a network
docker create -p 27017:27017 --name [container name] --network [network name] -e MONGO_INITDB_ROOT_USERNAME=[username] -e MONGO_INITDB_ROOT_PASSWORD=[password] mongo
- Create from Dockerfile:
docker compose up - Delete all that the command created
docker compose down
```
docker compose -f docker-compose-dev.yml up
```