kreamik
kreamik

Reputation: 627

docker compose how to run multi images with no service

I am new to Docker and still testing different features of docker.

Currently, I am learning docker-compose with the pure OS loaded (alpine and ubuntu)

my docker-compose yaml file :

    version: '3.7'
    services:
      alpine1:
        image: alpine:latest
      ubuntu2:
        image: ubuntu:latest

Output of docker ps -a

    CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
    2004175db96b        ubuntu:latest       "/bin/bash"         25 minutes ago      Exited (0) 3 seconds ago                        dockerize_ubuntu2_1
    eaae1f731b71        alpine:latest       "/bin/sh"           25 minutes ago      Exited (0) 25 minutes ago                       dockerize_alpine1_1

These images are still pure image, I can not start both the container,

with docker I usually use :

docker run -t alpine

then I can start the container.

Please help me with my problem above.

I still want to run the container from pure images.

Upvotes: 0

Views: 101

Answers (1)

LinPy
LinPy

Reputation: 18618

Just add commands to prevent the containers to be exited:

version: '3.7'
services:
  alpine1:
    image: alpine:latest
    command: tail -f /dev/null
  ubuntu2:
    image: ubuntu:latest
    command: tail -f /dev/null

start them:

docker-compose up -d

Upvotes: 1

Related Questions