I have a docker-compose file as follows:
version: '3.8'
services:
signup:
container_name: signup
build: .
ports:
- "88:80"
image: sgc-signup:Dockerfile
networks:
- test
restart: always
networks:
test:
external:
name: test
And a docker file of:
FROM php:7.2-apache
COPY src/ /var/www/html/
The working directory for this container is:
sgc-signup
src
footer.php
functions.php
index.php
navbar.php
styling.css
docker-compose.yml
Dockerfile
The console when i run the container locally returns the following error regarding styling .css:
Failed to load resource: net::ERR_CONNECTION_REFUSED
Almost identical code has worked in another container for signin.
I have tried clearing the cache as well as docker-compose up --build and a couple of similar solutions found on stack overflow with no joy so far.
Related
I am following this article to run Cypress test with Docker.
I encountered issue where I need cypress.json file to be included in docker-compose.yaml. Here is example of my docker-compose.yamlfile looks like
version: '3.3'
services:
cypress:
image: "cypress/included:7.7.0"
enviroment:
- HTTP_PROXY=somekind_url
working_dir: location of cypress files
volumes:
- ./:/cypress
command: [-b, chrome]
My question is how to tell in docker-compose.yaml to grab my cypress.json that is located in root project directory?
You can see how in https://github.com/cypress-io/cypress-example-docker-compose-included/blob/master/docker-compose.yml
volumes:
- ./cypress:/cypress
- ./cypress.json:/cypress.json
./cypress.json it's your local file, and /cypress.json it's the file into the container.
Running docker-compose commands like build and up works.
However when I try to connect docker with VS Code I get this error:
The Compose file is invalid because:
Service your-service-name-here has neither an image nor a build context specified. At least one must be provided.
This is the compose file:
version: '3'
services:
db:
image: postgres
ports:
- "5432:5432"
web:
build: .
command: bin/rails server --port 3000 --binding 0.0.0.0
ports:
- "3000:3000"
links:
- db
volumes:
- .:/myapp
Look at your devcontainer.json in the .devcontainer folder. Mine had an autogenerated docker-compose.yml from a previous experiment and it was a partially-filled template which could not work, hence the error message.
Found this by looking carefully at the command VSCode was trying to execute (the -f argument).
Cleaning up the .json config file solved the issue.
I very probably that your should be specific build context
build:
context: . # if you stay on root project
I'm trying to migrate working docker config files (Dockerfile and docker-compose.yml) so they deploy working local docker configuration to docker hub.
Tried multiple config file settings.
I have the following Dockerfile and, below, the docker-compose.yml that uses it. When I run "docker-compose up", I successfully get two containers running that can either be accessed independently or will talk to each other via the "db" and the database "container_name". So far so good.
What I cannot figure out is how to take this configuration (the files below) and modify them so I get the same behavior on docker hub. Being able to have working local containers is necessary for development, but others need to use these containers on docker hub so I need to deploy there.
--
Dockerfile:
FROM tomcat:8.0.20-jre8
COPY ./services.war /usr/local/tomcat/webapps/
--
docker-compose.yml:
version: '3'
services:
app:
build:
context: .
dockerfile: Dockerfile
ports:
- "8089:8080"
volumes:
- /Users/user/Library/apache-tomcat-9.0.7/conf/tomcat-users.xml:/usr/local/tomcat/conf/tomcat-users.xml
depends_on:
- db
db:
image: mysql:5.7
container_name: test-mysql-docker
ports:
- 3307:3306
volumes:
- ./ZipCodeLookup.sql:/docker-entrypoint-initdb.d/ZipCodeLookup.sql
environment:
MYSQL_ROOT_PASSWORD: "thepass"
Expect to see running containers on docker hub, but cannot see how these files need to be modified to get that. Thanks.
Add an image attribute.
app:
build:
context: .
dockerfile: Dockerfile
ports:
image: docker-hub-username/app
Replace "docker-hub-username" with your username. Then run docker-compose push app
I'm following this link to making a docker-compose.yml file but it will giving me the same issue does not find the docker file while I'm mentioning that in the docker-compose.yml see my code:-
version: '2'
services:
web:
build: .
ports:
- "8000:8000"
users:
build:
context: ./users
dockerfile: Dockerfile
image: cinema/movies
container_name: cinema-movies
environment:
VIRTUAL_HOST: movies.local
And docker-compose.yml file is in the bkapiv folder the folder structure is :-
bkapiv(Folder)------users(Folder)
| |
| ------Dockerfile
|
---------docker-compose.yml
How will I resolve my issue that I will run my first api on local using docker.
web:
build: .
I think error throwing from web container, commented out the users and run the docker-compose, you need a Dockerfile in web too. Also try other way around. The you can understand which container produce the error. Because users looks fine for me according to your folder structure. Plus you have an extra space in services:
The problem is in the web service, you specified that it should build a Dockerfile in your current dir but there is no Dockerfile there.
I have the following docker-compose.yml file:
version: "3.3"
services:
api:
build: ./api
expose:
- '8080'
container_name: 'api'
ports:
- "8080:8080"
depends_on:
- db
stdin_open: true
tty: true
networks:
- api-net
db:
build: ./db
expose:
- '27017'
container_name: 'mongo'
ports:
- "27017:27017"
networks:
- api-net
networks:
api-net:
driver: bridge
and the Dockerfile for the api container is as follows:
FROM iron/go:dev
RUN mkdir /app
COPY src/main/main.go /app/
ENV SRC_DIR=/app
ADD . $SRC_DIR
RUN go get goji.io
RUN go get gopkg.in/mgo.v2
# RUN cd $SRC_DIR; go build -o main
CMD ["go", "run", "/app/main.go"]
If I run the code for main.go outside of a container it runs as expected, however if I try to run the container as part of docker-compose I get an exit 0. I have seen other threads on stackoverflow that have suggested using stdin_open and tty, but these have not helped. I have also tried creating an .env file in the same directory I issue docker-compose up from with COMPOSE_HTTP_TIMEOUT=8000 in it and this has not worked either. I am looking for helped and suggestions as to what I need to do in order for my api container to stay up.
I know that --verbose can be issued with docker-compose, however I'm not sure what I should be looking for in the output that this produces.
I finally managed to get to the bottom of this, in my code which worked outside of a container I had:
http.ListenAndServe("localhost:8080", mux)
the fix was to simply remove localhost such that I now have:
http.ListenAndServe(":8080", mux)