-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathDocker notes.yaml
More file actions
58 lines (44 loc) · 1.88 KB
/
Docker notes.yaml
File metadata and controls
58 lines (44 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
Docker installation on Mac:
brew install --cask docker
open /Applications/Docker.app
docker --version
Find the installation location:
find /Applications/Docker.app -name docker
Run Docker Using the Full Path:
/Applications/Docker.app/Contents/Resources/bin/docker --version
Add to PATH:
export PATH="/Applications/Docker.app/Contents/Resources/bin:$PATH"
Then, you'll need to apply the changes with:
source ~/.zshrc
###########################################################################
Docker file instructions:
Create a Dockerfile like this:
#Use the official image as a parent image of python from Dockerhub:
FROM python:3.9
#create a new directory in the container. It automatically moves into it:
WORKDIR /fastapi-app
#copying the requirements file to the new directory in the container:
COPY requirements.txt .
#installing the requirements file:
RUN pip install -r requirements.txt
#copying the app folder to the new directory in the container:
COPY ./app ./app
#Run command in terminal to start the app:
CMD ["python", "./app/main.py"]
docker build -t <name_of_docker_image> .
docker run <name_of_docker_image>
If you want to map the ports from the container to the "outside" world:
docker run -p 8000:8000 <name_of_docker_image> #map the ports
If we want to list all dockers running:
docker ps
If we want to list all docker images:
docker image ls
To add a tag to a docker image:
docker tag <name_of_docker_image>:latest mascobot/<name_of_docker_image>:marcotag88
To login and logout:
docker login
docker logout
To push to image with tag to DockerHub:
docker push mascobot/<name_of_docker_image>:marcotag88 <--- this is the name of the image in DockerHub and if it doesn't exist it will create a new one as Public (default)
If we want to open a terminal inside the container once it's already running:
docker exec -it <container ID> /bin/sh