How to run ubuntu Or Alpine containers using docker-compose?

Hi,

I am new to docker, trying to practice docker-compose commands! My doubt is how to run ubuntu/alpile kind of operating system images using docker-compose?

Here is the docker-compose.yml file:
cat docker-compose.yml
version: “3”
services:
myalpine:
image: alpine
command: sh
myubuntu:
image: ubuntu

Here is the output when i run “docker-compose up” command.
docker-compose up
WARNING: The Docker Engine you’re using is running in swarm mode.

Compose does not use swarm mode to deploy services to multiple nodes in a swarm. All containers will be scheduled on the current node.

To deploy your application across the swarm, use docker stack deploy.

Starting docker-compose-1_myubuntu_1 … done
Starting docker-compose-1_myalpine_1 … done
Attaching to docker-compose-1_myubuntu_1, docker-compose-1_myalpine_1
docker-compose-1_myubuntu_1 exited with code 0
docker-compose-1_myalpine_1 exited with code 0

[root@ip-172-31-90-241 docker-compose-1]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

None of the containers are running…! :frowning:

Can someone help me, how to run these images using docker-compose?

Thank you in advvance.

You did! But just having them launch a shell isn’t very interesting; the shell didn’t have any input and exited successfully (“exited with code 0”).

For a next step I’d recommend reading Docker’s tutorial on writing and running custom images. You can then plug these into your docker-compose.yml to build up an application built on top of these base Linux distributions.

1 Like

Will you be using swarm?

If not… you must configure you docker as standalone and start your environment again:

$ docker-compose up -d

Thank you for your reploy.

Can you help me to get docker-compose file for this docker run command?
docker run -itd ubuntu

No, it didn’t work as expected.

I just simply need a dokcer-compose file for this docker run command.

Can you help me to get docker-compose file for this docker run command?
docker run -itd ubuntu

It is literally exactly what you quoted (except without the tty input, and Docker Compose handles running it in the background).

You’ve got this part down; your next step should be plugging in a custom Dockerfile so you can make the container do something interesting.

Thank you for your quick response.

What i can understand is, we can’t run container with tty option with docker-compose. Where as we can run the same thing with docker run -it ubuntu option.

Please correct me if i am wrong.

You can, but what you’re describing isn’t really an effective use of Docker.

(If nothing else, consider that to change the value of this flag you have to stop, delete, and recreate your container, which will delete its filesystem. So anything you’ve done in an interactive shell in that container is going to get lost, every time you change a basic Docker startup option.)

Thank you. I got your point.

This is the point i was actually looking for …

“So anything you’ve done in an interactive shell in that container is going to get lost, every time you change a basic Docker startup option”

Ok, so once I have ubuntu running in a container, how do I access it? Most of the apps I have built are accessed via web browser, but there is no port for the Ubuntu image?

Hi @advithdevops,

You need to insert the ‘tty: ture’ field in both services e.g.,

version: "3"

services:
  myalpine:
    image: alpine
    tty: true
  myubuntu:
    image: ubuntu
    tty: true

Run your compose file with ‘-d’ as:

docker-compose up -d

Thanks bro… It’s work