Hector Esteban
Hector Esteban

Reputation: 1111

Run a repository in Docker

I am super new to Docker. I have a repository (https://github.com/hect1995/UBIMET_Challenge.git) I have developed in Mac that want to test it in a Ubuntu environment using Docker. I have created a Dockerfile as:

FROM ubuntu:18.04

# Update aptitude with new repo
RUN apt-get update \
 && apt-get install -y git

RUN git clone https://github.com/hect1995/UBIMET_Challenge.git

WORKDIR /UBIMET_Challenge

RUN mkdir build

WORKDIR build

RUN cmake ..

RUN make

Now, following some examples I am running:

docker run --publish 8000:8080 --detach --name trial

But I do not see the output of the terminal from the docker to see what is going on. How could I create this docker and check what things I need to add and so on and so forth while inside the docker

Upvotes: 1

Views: 4484

Answers (2)

lovelinux
lovelinux

Reputation: 39

TLDR

add '-it' and remove '--detach'

or add ENTRYPOINT in Dockerfile and use docker exec -it to access your container

Longer explanation:

With this command

docker run --publish 8000:8080 --detach --name trial image_name

you tell docker to run image image_name as container named trial, expose port 8080 to host and detach (run in background).

Your Dockerfile does not mention which command should be executed (CMD, ENTRYPOINT), however your image extends 'ubuntu:18.04' image, so docker will run command defined in that image. It's bash.

Your container by default is in non interactive mode so bash has nothing to do and simply exits. Check this with docker ps -a command.

Also you have specified --detach command which tells docker to run container in background.

To avoid this situation you need to remove --detach and add -it (interactive, allocate pseudo-tty). Now you can execute commands in your container.

Next step

Better idea is to set ENTRYPOINT to your application or just hang container with 'sleep infinity' command.

try (sleep forever or run /opt/my_app):

docker run --publish 8000:8080 --detach --name trial image_name sleep infinity

or

docker run --publish 8000:8080 --detach --name trial image_name /opt/my_app

You can also define ENTRYPOINT in your Dockerfile

ENTRYPOINT=sleep infinity 

or

ENTRYPOINT=/opt/my_app

then use

docker exec -it trial bash #to run bash on container
docker exec trial cat /opt/app_logs #to see logs
docker logs trial # to see console output of your app

Upvotes: 1

The Dembinski
The Dembinski

Reputation: 1519

You want to provide and ENTRYPOINT or CMD layer to your docker file I believe.

Right now, it configures itself nicely when you build it - but I'm not seeing any component that points to an executable for the container to do something with.

You're probably not seeing any output because the container 'doesn't do anything' currently.

Checkout this breakdown of CMD: Difference between RUN and CMD in a Dockerfile

Upvotes: 0

Related Questions