![]() ![]() The restart directive is used to indicate that the container should always restart (after a crash or system reboot, for example).At this point, the section contains a single container based on the official Alpine distribution: Version : '3' services : distro : image : alpine restart : always container_name : Alpine_Distro entrypoint : tail -f /dev/nullĮach entry in the services section will create a separate container when docker-compose is run. See the Compose File reference for details. Many other configuration directives are available. Link this service to any other services in the Docker Compose file by specifying their names here. Maps a port from the container to the host in the following manner: host:container Sets a service as a dependency for the current block-defined container Mounts a linked path on the host machine that can be used by the containerĭefine environment variables to be passed in to the Docker run command. Tells the container to restart if the system restarts. In the case of the example Dockercompose file, db is a variable for the container you are about to define. Specifies the location of the Dockerfile that will be used to build this container. This directive can be used instead of image. Using this directive assumes that the specified image already exists either on the host or on Docker Hub. Sets the image that will be used to build the container. Here are some of the common directives used to set up and configure containers: Directive Most of this guide will focus on setting up containers using the services section. Mounts a linked path on the host machine that can be used by the container. You can change the settings of the default network, connect to an external network, or define app-specific networks. This section is used to configure networking for your application. ![]() This section defines the containers that will be started as a part of the Docker Compose instance. In Docker a service is the name for a “Container in production”. This guide will use Version 3 throughout. Specifies the Compose file syntax version. Stop and remove the containers: docker-compose downĪ docker-compose.yml file is organized into four sections: Directive You can also use docker ps to further explore the resulting configuration: docker ps Navigate to 192.0.8.1:8000/wordpress in a web browser to see your newly installed WordPress application. You now have a WordPress container and MySQL container running on your host. Just as when running a single container with docker run, the -d flag starts the containers in detached mode. This will build and run the db and wordpress containers. Save the file and run Docker Compose from the same directory: docker-compose up -d Version : '3' services : db : image : mysql:5.7 volumes : - db_data:/var/lib/mysql restart : always environment : MYSQL_ROOT_PASSWORD : somewordpress MYSQL_DATABASE : wordpress MYSQL_USER : wordpress MYSQL_PASSWORD : wordpress wordpress : depends_on : - db image : wordpress:latest ports : - "8000:80" restart : always environment : WORDPRESS_DB_HOST : db:3306 WORDPRESS_DB_USER : wordpress WORDPRESS_DB_PASSWORD : wordpress volumes : db_data: ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |