Revel and Docker container - docker

I am attempting to create a docker container that contains the revel skeleton app. Everything seems to build OK and the container is created but when I go to localhost:9000 in my browser nothing comes up.
To make sure my environment is working properly I created a simple hello world go app and created a docker container for it. It worked OK using the same port 9000. This makes me think that there is something not configured properly in my dockerfile.
Dockerfile:
#Compile stage
FROM golang:1.11.4-alpine3.8 AS build-env
ENV CGO_ENABLED 0
RUN apk add --no-cache git
ADD . /go/src/revelapp
# Install revel framework
RUN go get -u github.com/revel/revel
RUN go get -u github.com/revel/cmd/revel
#build revel app
RUN revel build revelapp app dev
# Final stage
FROM alpine:3.8
EXPOSE 9000
WORKDIR /
COPY --from=build-env /go/app /
ENTRYPOINT /run.sh
Docker command used:
docker build -t revelapp . && docker run -p 9000:9000 --name revelapp revelapp
After command is executed and container is created the console shows:
INFO 17:25:01 app run.go:32: Running revel server
INFO 17:25:01 app plugin.go:9: Go to /#tests to run the tests.
Revel engine is listening on.. localhost:9000
When I go to localhost:9000 I would expect to see the text It Works!

You're listening on localhost:9000, so 127.0.0.1 points to your container and not your local machine.
You have two solutions to make it work:
Listen on 0.0.0.0:9000
Use --network="host" in your docker run command: 127.0.0.1 in your docker container will point to your docker host.

Related

I am able to run the container in docker but unable to view in the browser

I am new to Docker. Firstly, I have created Dockerfile with in source code location.
Here is my Dockerfile
FROM nginx:latest
RUN mkdir /app
COPY . /app
EXPOSE 8000
lately, build an image using: docker build -t mywebapp:v1 .
and i have run the container using following command:
docker run -d -p 8000:8000 mywebapp:v1
problem is : container is running using port 8000, but unable to view in the browser
http://192.168.13.135:8000
please help me out in this problem inorder to view in the browser.

There is no result after auto-deploy an app using GitLab CI/CD on Ubuntu

In my laptop with npm run serve can load my Vue app on http://localhost:8080 so i initialized git and push the app into a new Gitlab repository then created Dockerfile as below:
FROM node:12.18.3 AS build-stage
WORKDIR /app
COPY package*.json .
RUN npm install
COPY . .
RUN npm run build
FROM php:7.3-apache AS production-stage
COPY --from=build-stage /app/dist /var/www/html
EXPOSE 80
CMD ["apachectl", "-D", "FOREGROUND"]
I built an image docker build -t vue-app . and run it in my laptop by docker run -d -p 80:80 --rm --name test-vue-app vue-app that works well
So to use Gitlab CICD to deploy this app on my self-hosted Ubuntu as a home server created followed .gitlab-ci.yml
image: docker
services:
- docker:dind
stages:
- deploy
step-deploy-prod:
stage: deploy
script:
- docker build -t vue-app .
- docker run -d -p 80:80 --rm --name testvueapp vue-app
also in another pc as server (with the fresh Ubuntu os), installed ufw, open-ssh, apache2 and php and set my Router up to check this pc worked well as a simple home server which was positive
So connected to server device with ssh and install and register gitlab-runner and Docker as well.
Although with running Gitlab Pipeline can get Job succeeded, couldn't see any changes or update in server and load the result of running container even directly in server machine
PS: by enabling apache2 on server device, i can load a simple php page on http://XX.XX.XX.XX (according to exist /var/www/html/index.php file) from any device but after running pipeline it doesn't work and if apache2 be enabled on server only can load php page instead Vue app

pwa-studio docker configuration dev-environmet

In order to work with pwa-studio I have to use docker due to the fact that I am using windows. So I made it in the simplest possible way for me with Dockerfile:
FROM node:10
RUN mkdir /app
WORKDIR /app
EXPOSE 3000
then I created container:
winpty docker run -it -p 3000:3000 --mount type=bind,source="$(pwd)",target=/app nfr:1.0 bash
all commands related to installation packages or running app I make being attached to container
Using address localhost:3000 I can see my app running since I expose the port.
PROBLEM:
One of the first configuration steps in pwa-studio is to add a custom hostname and SSL cert, which is done with
yarn buildpack create-custom-origin ./
As a result app inside container is no longer available via localhost:3000 but via domain name, in my case it is: https://pwa-aynbv.local.pwadev:3000/
How to configure docker to expose this domain outside of the container ?
Thanks in advance for any help

DOCKER: Running shell script inside container hangs

I am currently trying to dockerize a codeigniter application cloned from here.
I used a base lamp stack image from docker hub found here
My dockerfile looks like this currently:
FROM firespring/apache2-php
WORKDIR /var/www/spaceship
COPY . .
EXPOSE 8000
CMD ["bin/server.sh"]
But when I try to run it it with:
$ docker run -p 1234:8000 spaceship
it hangs.
I tried verifying if my base image was not compatible with it:
$ docker run --rm -it --entrypoint=/bin/bash spaceship
root#fa09751cd081:/var/www/spaceship# ls
Dockerfile README.md application bin composer.json composer.lock favicon.ico public vendor
root#fa09751cd081:/var/www/spaceship# bin/server.sh
PHP 5.5.9-1ubuntu4.24 Development Server started at Sat Apr 6 02:51:44 2019
Listening on http://127.0.0.1:8000
Document root is /var/www/spaceship/public
Press Ctrl-C to quit.
but apparently it works inside the container locally.
So I guess my question is how do i write the proper dockerfile for this?
Can you try and add "-d" to your docker run command:
docker run -d -p 1234:8000 spaceship

Cannot access server running in container from host

I have a simple Dockerfile
FROM golang:latest
RUN mkdir -p /app
WORKDIR /app
COPY . .
ENV GOPATH /app
RUN go install huru
EXPOSE 3000
ENTRYPOINT /app/bin/huru
I build like so:
docker build -t huru .
and run like so:
docker run -it -p 3000:3000 huru
for some reason when I go to localhost:3000 with the browser, I get
I have exposed servers running in containers to the host machine before so not sure what's going on.
From the information provided in the question if you see logs of the application
(docker logs <container_id>) than the docker application starts successfully and it looks like port exposure is done correctly.
In any case in order to see ports mappings when the container is up and running you can use:
docker ps
and check the "PORTS" section
If you see there something like 0.0.0.0:3000->3000/tcp
Then I can think about some firewall rules that prevent the application from being accessed...
Another possible reason (although probably you've checked this already) is that the application starts and finishes before you actually try to access it in the browser.
In this case, docker ps won't show the exited container, but docker ps -a will.
The last thing I can think of is that in the docker container itself the application doesn't really answer the port 3000 (I mean, maybe the startup script starts the web server on some other port, so exposing port 3000 doesn't really do anything useful).
In order to check this you can enter the docker container itself with something like docker exec -it <container_id> bash
and check for the opened ports with lsof -i or just wget localhost:3000 from within the container itelf
Try this one, if this has any output log. Please check them...
FROM golang:latest
RUN apt -y update
RUN mkdir -p /app
COPY . /app
RUN go install huru
WORKDIR /app
docker build -t huru:latest .
docker run -it -p 3000:3000 huru:latest bin/huru
Try this url: http://127.0.0.1:3000
I use the loopback

Resources