I try to deploy asp.net docker on aws
This is my Dockerfile (from microsoft docker example)
FROM microsoft/aspnet
COPY . /app
WORKDIR /app
RUN ["kpm", "restore"]
EXPOSE 80:80
ENTRYPOINT ["k", "kestrel"]
The problem is. I can use commandline to call [ docker run -p 80:80 image ] to run docker properly
But when I use AWS Beanstalk to deploy my dockerfile. It cannot map public port to docker port automatically. I need to run docker run -p again to make it usable
At start there are image that's work and container that run. But it seem it can't map port so it die. I then need to run a run command with -p again to make it work
I have no clues how aws will run docker with -p on which port. please help me
Related
I have deployed my linux container in AWS ECS, and I can access it over port 80 by using an AWS load balancer.
How do I make them visible by adding certificate on 443. I have tried just exposing the port, but I also need to add the certificate. I cant use docker-compose as AWS ECS doesn't support that and I need to add everything in the single application Dockerfile.
What are the steps for adding the certificate in a dockerfile?
My dockerfile looks like this now
FROM node:10
WORKDIR /usr/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 8000
CMD [ "node", "env.js"]
I have launch EC2 ubuntu instance and security group for this is instance allows 22,80,443 ports from 0.0.0.0/0.
Now i have installed docker on this EC2 instance.Then i have created an apache2 container and also mapped the port to access from browser using below command
sudo docker run -p 80:80 -t -i ubuntu /bin/bash
Then i create an lampstack conatiner and tried to map port using below command
sudo docker run -p 443:443 -t -i linode/lamp /bin/bash
Now docker ps gives me below
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS Name
d0751e67fd69 linode/lamp "/bin/bash" 4 min Up 4 0.0.0.0:443>443/tcp
affectionate_hamilton
0fb4e13a272a ubuntu "/bin/bash" 11 minutes 0.0.0.0:80->80/tcp
vigorous_robinson
When i take the public ip of my EC2 machine and put in browser i can see the apache page but how can i assess my Lampstack page ?
Please correct me if i have done port mapping incorrectly
You only need the LAMP container and in that one you should map the port 80:
sudo docker run -d --name lamp -t -p 80:80 linode/lamp top
Check that the container is up and running:
sudo docker ps --filter name=lamp
Now start the services:
sudo docker exec -ti lamp service apache2 start
sudo docker exec -ti lamp service mysql start
Test your setup from host:
curl http://localhost
If you want to test a connection from a different container you can start a separate ubuntu container that links to your original container "lamp":
docker run -ti --rm --link lamp --name ubuntu-box ubuntu bash
Inside the container install curl and test your connection:
apt update && apt-get install curl -y
curl http://lamp
I have a linux AWS instance. I am running the following script on it:
#!/usr/bin/env bash
#This script installs java, sbt and the application
#Run this script on a new EC2 instance as the user-data script, which is run by `root` on machine start-up.
sudo yum update -y
sudo yum install -y docker
sudo service docker start
docker run repo/carrie
Everything installs and I get the below message in the logs:
REST interface bound to /0.0.0.0:8080
However when I try to actually access the port like so:
curl 0.0.0.0/8080
I get the below message:
Failed to connect to 0.0.0.0 port 8080: Connection refused
I have tried editing the inbound rules so that 8080 is open but it doesn't seem to work. Maybe because I'm editing the rules after the instance has already launched?
You have to publish the container's port to the host in the docker run command
$ docker run --help
...
-p, --publish list Publish a container's port(s) to the host
...
The last line of your script should look like this if the process in the container listens on port 80:
docker run -p 8080:80 repo/carrie
The container gets its own interface, hence host's 0.0.0.0 is not applicable.
Tell docker to bind container port 8080 out to the host:
docker run -p 8080:8080 repo/carrie
I've got an app running Flask_sqlalchemy in a Docker container.
The container wasn't running properly so I dived in and tried running the application and get the following error:
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection refused
Is the server running on host "DBNAME.XXXXXXXXXX.eu-west-1.rds.amazonaws.com" (000.000.000.000) and accepting
TCP/IP connections on port 5432?
The application works fine outside the container, and I can't work out what's going on.
Could it be something to do with the AWS-RDS security groups? They're currently configured to only accept inbound connections from our office where development takes place.
EDIT:
This is my Dockerfile:
FROM ubuntu:latest
RUN apt-get update -y
RUN apt-get install -y python-pip python-dev build-essential libpq-dev python-shapely
COPY . /src
WORKDIR /src
RUN pip install -r requirements.txt
EXPOSE 5000
CMD ["python", "application.py"]
And this is the Docker Run command I'm doing:
docker run -d -p 5000:5000 container_name
Thanks
I had exactly the same problem ;) but solved it by ensuring the following:
The AWS ELB environment configuration is Generic Docker (not preconfigured for Python).
The environment is created inside of a VPC that contains the RDS instance.
The RDS instance is listening to the right port (PostgreSQL:5432) from the VPC security group (this should already be the case).
I have a jenkins instance running inside a docker container that's listening on port 8181.
Example URL of the jenkins instance:
http://ec2-34-155-164-97.us-west-2.compute.amazonaws.com/
I have a tomcat docker instance that's listening on port 8383 running inside the jenkins docker container.
I can access jenkins instance from my local browser. Is there any possible way that I can access my docker tomcat instance from my local browser?
Here is my docker run command:
docker run -d -v /var/run/docker.sock:/var/run/docker.sock \ -v $(which docker):/usr/bin/docker -p 8181:8080 jenkins-dsl
Please provide your suggestions.
It sounds like your docker run command simply needs to expose the port that your nested tomcat server is running on.
To do this, you need to pass in -p argument into your command. The -p argument is for binding a host port to the docker container's port:
-p <host_port>:<container_port>
You can pass in as many -p arguments as you want to bind multiple ports.
So if the docker tomcat server is running on port 8383 within the Jenkins docker container, then you can do something like this:
-p 8383:8080
Full command example:
docker run -d -it -p 8383:8080 --name tomcatServer docker-tomcat
I would assume that this would allow you to access tomcat server using the example URL provided like so:
http://ec2-34-155-164-97.us-west-2.compute.amazonaws.com:8383
However, you'd have to ensure your AWS Security Group will allow traffic to port 8383.
EDIT: Updated answer to reflect the resolution we discussed in the comments.
Edited
I could able to launch tomcat by specifying the port in the URL and opening the port in EC2 instance.
http://ec2-34-155-164-97.us-west-2.compute.amazonaws.com:8383
Latest Docker installation guide for Tomcat clearly says you will get this error when you launch it for the first time
You can then go to http://localhost:8888 or http://host-ip:8888 in a browser (noting that it will return a 404 since there are no webapps loaded by default).
its because you do not have any apps in the default webapps folder of Tomcat. your latest Tomcat docker image has the default apps in the "webapps.dist" folder, you have to copy it to "webapps" folder. Do the Following commands
# docker exec -it tomcat-container /bin/bash
# cd webapps.dist
# cp -R * ../webapps
"tomcat-container" is your container name.
now refresh your browser you will get it. if not let me know