This repository contains the source code and instructions for running a User CRUD Application using Docker. The application listens on port 3000
by default but can be mapped to any host port during runtime.
Before you begin, ensure that the following tools are installed on your system:
- Docker: Install Docker from the official website.
- Git (optional): If you need to clone this repository.
Verify your Docker installation by running:
docker --version
To build the Docker image for the application, follow these steps:
-
Navigate to the root directory of the project where the
Dockerfile
is located. -
Run the following command to build the image:
docker build -t visitha/user-crud-v1.0.0 .
-t visitha/user-crud-v1.0.0
: Tags the image with the namevisitha/user-crud-v1.0.0
..
: Specifies the current directory as the build context.
-
Verify that the image has been built successfully:
docker images
You should see an entry for
visitha/user-crud-v1.0.0
.
Once the image is built, you can run the container using the following command:
By default, the application listens on port 3000
. To map it to the same port on your host machine:
docker run -p 3000:3000 visitha/user-crud-v1.0.0
If you want to map the application's port 3000
to a different port (e.g., 3001
) on your host machine:
docker run -p 3001:3000 visitha/user-crud-v1.0.0
Alternatively, you can use the image ID instead of the tag:
docker run -p 3001:3000 <imageID>
Replace <imageID>
with the actual image ID obtained from docker images
.
After starting the container, the application will be accessible via the specified host port. For example:
-
If you used the default mapping (
3000:3000
), access the app at:http://localhost:3000
-
If you used a custom mapping (
3001:3000
), access the app at:http://localhost:3001
To stop the running container:
-
List all running containers:
docker ps
-
Identify the container ID or name of your application.
-
Stop the container using:
docker stop <containerID_or_name>
-
Environment Variables: If your application requires environment variables, you can pass them using the
-e
flag:docker run -p 3001:3000 -e ENV_VAR_NAME=value visitha/user-crud-v1.0.0
-
Persistent Data: If your application uses a database or requires persistent storage, consider using Docker volumes:
docker run -p 3001:3000 -v /host/path:/container/path visitha/user-crud-v1.0.0
-
Logs: To view the logs of a running container:
docker logs <containerID_or_name>