https://github.com/bennycode/workshop-docker
https://github.com/bennycode/workshop-docker
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/bennycode/workshop-docker
- Owner: bennycode
- Created: 2022-01-25T12:59:02.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-06-19T08:03:45.000Z (almost 2 years ago)
- Last Synced: 2025-01-27T23:46:41.668Z (about 1 year ago)
- Language: JavaScript
- Size: 42 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# workshop-docker
## Commands
Level 1:
- `FROM`
- `RUN`
- `WORKDIR`
- `COPY`
- `CMD`
Level 2:
- `ENV`
- `EXPOSE`
- `ENTRYPOINT`
Examples:
- Shell Form: `RUN chmod + x ./hello.sh`
- Exec Form: `RUN ["python", "hello.py"]`
- https://goinbigdata.com/docker-run-vs-cmd-vs-entrypoint/
## Learnings
- Docker container will be automatically stopped when there is no infinite command (ex. using a simple command like `console.log` without an infinite loop surrounding it)
## Images
### Build Image
```yml
docker build .
docker build -f Dockerfile -t our-server .
```
### List Images
```yml
docker image list
docker image ls
```
### Remove Images
```yml
docker image rm
docker rmi
# Example
docker image rm lambot-1_tws:latest
```
## Containers
### Run Containers
```yml
docker run -d
docker run -d -p : our-server:latest
docker run --env-file=.env -d -p 8080:1339 our-server:latest
docker run --name some-container -e POSTGRES_USER=root -d postgres
# Example:
docker run -d our-server:latest
docker run -d -p 8080:80 our-server:latest
```
### Show Containers
```yml
# Show running containers
docker ps
# Show all containers (running & stopped)
docker ps -a
```
### View Container Logs
```yml
docker logs
docker logs -f
```
### Remove Container
```yml
docker rm
```
### Publish Images
- Docker Registries: Docker Hub, GitHub's Docker Registry (https://ghcr.io), Google Container Registry
```yml
docker login ghcr.io --username phanatic --password-stdin
docker tag app ghcr.io/phanatic/app:1.0.0
docker push ghcr.io/phanatic/app:1.0.0
```
## Docker Compose
> [!IMPORTANT]
> The "docker-compose" command belongs to Docker Compose V1
> The "docker compose" command belongs to Docker Compose V2
Preferred syntax is V2:
```bash
docker compose --profile dev up -d
```
### Start Composition
```yml
docker-compose up -d
docker-compose -f docker-compose.yml up -d
docker-compose -p ninja-workshop up -d
docker-compose -p ninja-workshop --env-file=.env up -d
docker-compose -p ninja-workshop --env-file=.env up -d --build # enforce new Image builds
docker-compose --profile dev up -d
```
### Terminate Composition
```yml
docker-compose -p ninja-workshop down
docker compose --profile dev down -v
```