Docker Community Forums

Share and learn in the Docker community.

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

docker

(Advithdevops) #1

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.


(David Maze) #2

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.


(Evertramos) #3

Will you be using swarm?

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

$ docker-compose up -d

(Advithdevops) #4

Thank you for your reploy.

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


(Advithdevops) #5

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


(David Maze) #6

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.


(Advithdevops) #8

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.


(David Maze) #9

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.)


(Advithdevops) #10

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”