📜  docker-compose.yml ubuntu - Shell-Bash (1)

📅  最后修改于: 2023-12-03 15:30:32.474000             🧑  作者: Mango

Docker Compose YAML File for Ubuntu with Shell-Bash

Introduction

Docker Compose is a tool for defining and running multi-container Docker applications. In this YAML file, we will explore how to create an Ubuntu container and run a Shell-Bash command inside it.

YAML File
version: '3'
services:
  ubuntu:
    image: ubuntu
    container_name: ubuntu_shell
    command: bash -c "echo 'Hello, world!'"
Explanation
  • version: '3' specifies the version of the Docker Compose file syntax to be used.
  • services section is used for defining the containers to be run.
  • ubuntu is the name of the container service we are defining.
  • image: ubuntu specifies the base image for the container to be used.
  • container_name: ubuntu_shell assigns a name to the container being created.
  • command: bash -c "echo 'Hello, world!'" specifies the command to run inside the container. In this case, we are running a simple echo command that outputs Hello, world!
Output

When we run the following command in the terminal:

docker-compose -f docker-compose.yml up

it will create and start the container defined in the YAML file. After it's finished running, the output should look like this:

ubuntu_shell | Hello, world!
Conclusion

In this example, we learned how to create a docker container with an Ubuntu base image and run a Shell-Bash command inside it using Docker Compose YAML. Docker Compose makes it straightforward to create and manage multi-container applications, and YAML provides a simple and elegant way to define the configuration of the containers.