docker dockerfile example
时间: 2023-10-12 11:21:24 浏览: 38
Here is an example Dockerfile:
```
# Set base image
FROM ubuntu:latest
# Set working directory
WORKDIR /app
# Copy application code to container
COPY . .
# Install required packages
RUN apt-get update && \
apt-get install -y python3 python3-pip && \
pip3 install -r requirements.txt
# Expose port
EXPOSE 8080
# Set environment variables
ENV FLASK_APP=app.py
# Start application
CMD ["flask", "run", "--host=0.0.0.0"]
```
This Dockerfile sets a base image of the latest Ubuntu release, sets the working directory to `/app`, copies the application code to the container, installs required packages including Python and its package manager `pip`, exposes port 8080, sets environment variables including the entry point of the application, and starts the application using the Flask web framework.
To build the Docker image, navigate to the directory with the Dockerfile and run:
```
docker build -t myimage .
```
This will create a Docker image with the tag `myimage`. To run the container, use:
```
docker run -p 8080:8080 myimage
```
This will start the container and map the host port 8080 to the container port 8080. The application can then be accessed at `http://localhost:8080`.