Step-by-Step Guide
1. Clone the Repository
Start by cloning the Docker Awesome Compose repository to your local environment. Use the following command:
git clone https://github.com/docker/awesome-compose.git
After cloning, navigate into the specific project directory you want to work with. For example, if you are using the Nginx and Golang example:
cd awesome-compose/nginx-golang
2. Build the Go Backend
Before you can start the Docker containers, you need to build the Go backend. The Go module is set to github.com/docker/awesome-compose/nginx-golang/backend
. Execute the following command to build the Go application:
cd backend
go build
Ensure that you do not use the -mod=vendor
option, as it is not applicable in this context. The output of the build will produce an executable file in the same directory.
3. Build and Start Docker Containers
From the root of the project directory, you can use Docker Compose to build and start the entire multi-container application. This is typically done with a docker-compose.yml
file that defines all the services, networks, and volumes needed for the application.
Run the following command:
docker-compose up --build
This command will initiate the build process of all the containers defined in the docker-compose.yml
file and then start them. The --build
flag ensures that Docker will rebuild the images from the Dockerfiles if any changes were detected.
4. Access the Application
Once the containers are up and running, you can access the application via a web browser. The typical setup for the Nginx and Golang application listens on port 8080. Open your browser and navigate to:
http://localhost:8080
Here, you should see the output from your running application, confirming that it is operational.
5. Stop the Containers
To stop the running containers, use the following command in the terminal:
docker-compose down
This command will terminate all the containers and remove them along with the associated network but retain the images.
6. Clean Up (Optional)
If you would like to remove the images after stopping the containers, you can add the --rmi all
option:
docker-compose down --rmi all
This will ensure that all related images are removed from your local environment.
Important Notes
Ensure that Docker and Docker Compose are installed and configured correctly in your system prior to executing any commands.
The above commands assume a Unix-like environment; you may need to use an equivalent command for different operating systems.
Follow these steps to effectively build and start the project from the Docker Awesome Compose repository.
Source: docker/awesome-compose