This file contains instructions for building the Docker image. A basic Dockerfile for a web app might look like this:
FROM <base_image>
WORKDIR /app
COPY . .
RUN <install_dependencies_command>
EXPOSE <port>
CMD ["<command_to_start_app>"]
docker build -t <image_name> .
Replace <image_name>
with a name for your image.
Run the Docker container:
docker run -d -p <host_port>:<container_port> <image_name>
-d
runs the container in detached mode (background).-p
maps the host port to the container port, allowing access from outside the container.
Replace <host_port>
with the port you want to access the app on (e.g., 8080) and <container_port>
with the port your app uses (defined in the Dockerfile, e.g., 5000).
Access the web app: Open a web browser and go to http://localhost:<host_port>
.
Verify the container is running:
docker ps
Stop the container:
docker stop <container_id or container_name>
Remove the container:
docker rm <container_id or container_name>
You can get inside your container and explore the file structure:
docker exec -it <your_container_name> bash
Once inside the container:
cd /usr/src/app
ls
This helps you confirm where index.html
should live.
If your change (like editing index.html
) is meant to be permanent or version-controlled:
docker build -t <image_name> .
docker stop <container_name_or_id>
docker rm <container_name_or_id>
docker run -d -p 8080:80 --name <new_container_name> <image_name>
Hint: /usr/src/app is a common convention in Linux, particularly when working with containers and Dockerfiles, to indicate the working directory for an application. It's a good location as it follows the Linux File System Hierarchy Standard (FHS), where /usr/src is traditionally used for source code
For fast, temporary changes:
docker cp index.html <container_name_or_id>:/path/to/index.html
You might need to restart the service inside the container depending on your setup (e.g., Nginx or Node.js).
For live development:
docker run -d -p 8080:80 \
-v "$(pwd)/your-folder:/usr/share/nginx/html" \
--name dev_container nginx
This syncs your local folder with the container’s web root, so file changes are reflected instantly.
Method | Use Case | Command Needed After Change? |
---|---|---|
Rebuild & Restart | Production, permanent | Yes: build, run |
docker cp | Quick patch | Only docker cp |
Volume mount | Active development | No, auto-updates |