Docker
Docker File for Python:
For creating FirstAPI Dockerfile:
WORKDIR /code
COPY ./requirement.txt /code/requirements.txt
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
COPY ./app /code/app
CMD ["uvicorn", "app.main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "80"]
COPY: copy necessary directory to workspace you created directory
File Structure:
app : it contains all the python project related things and executables.
.dockerignore: it contains all the ignore files while building the docker.
requirement.txt: it contains all the modules to be installed from python through pip.
Docker build commands:
Go to the app directory for build image and run:
è docker build -t getting-started .
“. “ => . shows the Dockerfile directory present in
è docker run -dp 3000:3000 getting-started
You use the -d flag to run the new container in “detached” mode (in the background). You also use the -p flag to create a mapping between the host’s port 3000 to the container’s port 3000. Without the port mapping, you wouldn’t be able to access the application.
è docker exec -it a27b7bf86813 /bin/sh
for executing command on code
run bash command
$ docker build -t image-name .
$ docker run -it --rm --name my-running-app image-name
Run single Python script:
$ docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp python:3 python your
-daemon-or-script.py
Docker file for React:
For Creating React Dockerfile:
Create React app
è npx create-react-app gdpu_api
Create Docker file
è Dockerfile.dev file create inside npm file
Dev Docker |
è
File Structure |
è Docker React repo files structure
è Docker Comand files:
docker build -f Dockerfile.dev -t react_gpdu .
docker run -d -it --rm -p 3000:3000 --name gpdu react_gpdu
docker ps
docker exec -it containerId bin/sh
docker stop container_id
Host on nginx:
Docker file for Production:
docker build -t react-nginx
.
docker run --rm -it -p
8080:80 react-nginx
docker run -d -it --rm -p 8080:80 --name gpdu react_gpdu
docker ps
docker exec -it 52c7368caa17 /bin/sh
Comments
Post a Comment