Utilizing Docker within the development environment of helixml/demo-recipes involves several key configurations and commands. This documentation outlines the necessary steps to set up and manage Docker containers specific to development needs.
Prerequisites
Ensure that Docker is installed and running on your development machine. The following commands are typically used to check if Docker is installed and to confirm its version:
docker --version
Setting Up Development Containers
Clone the Repository
Begin by cloning the helixml/demo-recipes repository to your local machine:
git clone https://github.com/helixml/demo-recipes.git cd demo-recipesDocker Compose Configuration
In the root directory, locate the
docker-compose.ymlfile. This file defines the services, networks, and volumes used for your local development setup.Here’s an example of the key configurations you might find in
docker-compose.yml:version: '3' services: app: build: context: . ports: - "3000:3000" volumes: - .:/app environment: - NODE_ENV=development- The
appservice describes the main application. buildspecifies the context for building the Docker image.portsmaps the container’s port 3000 to your local port 3000.volumesmounts your current directory to the/appdirectory inside the container, allowing real-time synchronization of your code changes.
- The
Creating the Docker Image
Build the Docker image defined in your Docker Compose configuration. Execute this command in the root of the cloned repository:
docker-compose buildStarting the Development Environment
Start the services defined in your
docker-compose.yml. This command will launch the necessary containers:docker-compose upYou can append the
-dflag to run the containers in detached mode:docker-compose up -dAccessing the Application
After the containers are up and running, the application should be accessible at
http://localhost:3000. Open this URL in your web browser to interact with the application.Stopping the Containers
To stop all running services without removing the containers:
docker-compose stopIf you wish to stop and remove the containers, use:
docker-compose down
Working with Shell Commands
To execute commands directly within a running container, use the exec command as follows. This is particularly useful for running scripts or debugging inside the container:
docker-compose exec app /bin/sh
You can also specify any command to run directly:
docker-compose exec app npm run your-script
Code Hot Reloading
With the volume configuration set up, any changes made to the local files will automatically reflect inside the container. Modifying TypeScript, CSS, or HTML files should trigger a hot reload, depending on your development server’s configuration.
Logging and Monitoring
To view logs from your containers, simply run:
docker-compose logs
You can follow logs for a specific service by using:
docker-compose logs -f app
Cleanup
To free up resources, you may want to remove unused Docker images and volumes. Use the following commands to prune dangling resources:
docker image prune
docker volume prune
Summary
Using Docker within the helixml/demo-recipes development environment streamlines the setup, ensures consistency, and enhances efficiency. By following the configurations and commands detailed above, expert developers can leverage Docker effectively for their local development workflows.
The information herein is sourced from the standard practices surrounding Docker usage in local development environments.