Nginx within docker start - docker

I can't start nginx in docker.
My Dockerfile:
FROM ubuntu
RUN apt-get install -y nginx
RUN useradd nginx
ADD nginx.conf /etc/nginx/
COPY conf.d/ /etc/nginx/conf.d
COPY vladislav.crt /etc/nginx/vladislav.crt
COPY vladislav.csr /etc/nginx/vladislav.csr
COPY vladislav.key /etc/nginx/vladislav.key
COPY dhparam.pem /etc/nginx/dhparam.pem
EXPOSE 80 443
CMD ["nginx", "-g", "daemon off;"]
I just build my image using next command
docker build -t custom_nginx .
docker run --name nginx_test custom_nginx
Where is my mistake?

#vijay
Sending build context to Docker daemon 73.22kB
Step 1/12 : FROM ubuntu:16.04
---> 77be327e4b63
Step 2/12 : RUN apt update
---> Using cache
---> 4fb44426c756
Step 3/12 : RUN apt-get install -y nginx
---> Using cache
---> 005b9faefee0
Step 4/12 : RUN useradd nginx
---> Using cache
---> b60713d5cce3
Step 5/12 : ADD nginx.conf /etc/nginx/
---> Using cache
---> a18a25afa878
Step 6/12 : COPY conf.d/ /etc/nginx/conf.d
---> Using cache
---> b1245c3f352d
Step 7/12 : COPY vladislav.crt /etc/nginx/vladislav.crt
---> Using cache
---> 5cc3e278e8fc
Step 8/12 : COPY vladislav.csr /etc/nginx/vladislav.csr
---> Using cache
---> e2d6824575a5
Step 9/12 : COPY vladislav.key /etc/nginx/vladislav.key
---> Using cache
---> ba28e5f7434b
Step 10/12 : COPY dhparam.pem /etc/nginx/dhparam.pem
---> Using cache
---> f6e3e5c5f3d1
Step 11/12 : EXPOSE 80 443
---> Using cache
---> bd10f8b63f23
Step 12/12 : CMD ["nginx", "-g", "daemon off;"]
---> Using cache
---> 0ac3851b312d
Successfully built 0ac3851b312d
Successfully tagged custom_nginx:latest
after that when I run it by that
root#maksym-X302UA:/etc/nginx# docker run --name nginx_test custom_nginx
I get only empty string

Related

Golang - problem with creating docker image

I try to make docker image, but when I run cmd in terminal.
sudo docker build testapi .
I get an error:
=> ERROR [6/6] RUN go build -o /app/testapi/cmd/test-api 0.3s
------
> [6/6] RUN go build -o /app/testapi/cmd/test-api:
#14 0.231 no Go files in /app
------
executor failed running [/bin/sh -c go build -o /app/testapi/cmd/test-api]: exit code: 1
File structure
/testapi
/cmd
/test-api
maing.go
/pkg
/...
Dockerfile
Dockerfile:
FROM golang:1.16-alpine
WORKDIR /app
COPY go.mod ./
RUN go mod download
COPY . ./
RUN go build -o /app/testapi/cmd/test-api
EXPOSE 8080
CMD [ "/testapi/cmd/test-api" ]
Try this way.
Also do not forget to add go.sum in Dockerfile if you have. COPY go.sum .
FROM golang:1.16-alpine
WORKDIR /app
COPY go.mod .
COPY . .
RUN go build -o main ./cmd/<FOLDER_NAME>
WORKDIR /dist
RUN cp /app/main .
EXPOSE 3000
CMD ["/dist/main"]
Works fine
Status: Downloaded newer image for golang:1.16-alpine
---> 7642119cd161
Step 2/9 : WORKDIR /app
---> Running in f8ad2994262c
Removing intermediate container f8ad2994262c
---> 6e079707cc3e
Step 3/9 : COPY go.mod .
---> c79a0cc04ff5
Step 4/9 : COPY . .
---> 897027112e73
Step 5/9 : RUN go build -o main ./cmd/api
---> Running in eb4579f1c339
Removing intermediate container eb4579f1c339
---> e41f6e5542a4
Step 6/9 : WORKDIR /dist
---> Running in 92115865d1ec
Removing intermediate container 92115865d1ec
---> 8152a0ebe4bc
Step 7/9 : RUN cp /app/main .
---> Running in 5c68cb195826
Removing intermediate container 5c68cb195826
---> 6f2e1fb8a611
Step 8/9 : EXPOSE 3000
---> Running in fba77820c1ec
Removing intermediate container fba77820c1ec
---> 182a624d807a
Step 9/9 : CMD ["/dist/main"]
---> Running in 164ba25694bd
Removing intermediate container 164ba25694bd
---> 7cf22cffc472
Successfully built 7cf22cffc472
Successfully tagged bla:latest
go build [-o output] [build flags] [packages]

Whs is my init.sh not found after succeful build?

My Dockerfile
FROM alpine:latest
WORKDIR /usr/src/app
COPY ./init.sh /usr/src/app
RUN chmod +x init.sh
CMD ["sh","-c","init.sh"]
Build goes OK
docker build . -t test
Sending build context to Docker daemon 3.072kB
Step 1/5 : FROM alpine:latest
---> e66264b98777
Step 2/5 : WORKDIR /usr/src/app
---> Running in 1ff4467854af
Removing intermediate container 1ff4467854af
---> 6b4f1fa4ca1c
Step 3/5 : COPY ./init.sh /usr/src/app
---> e61e55063baa
Step 4/5 : RUN chmod +x init.sh
---> Running in ae3724c0f595
Removing intermediate container ae3724c0f595
---> 3c2cd99a30b9
Step 5/5 : CMD ["sh","-c","init.sh"]
---> Running in 9df8c7d70e38
Removing intermediate container 9df8c7d70e38
---> bd9c9af6380d
Successfully built bd9c9af6380d
Successfully tagged test:latest
I got this
docker run -it test
sh: init.sh: not found
Why?
Use ./init.sh to execute the script, provided that the shell script has a proper shebang like #!/bin/sh on the top:
FROM alpine:latest
WORKDIR /usr/src/app
COPY ./init.sh /usr/src/app
RUN chmod +x init.sh
CMD ["sh", "-c", "./init.sh"]
Note that it's actually not necessary, and can be shortened as CMD ./init.sh.

docker build run paused ,can any one help me

its very strange,when i run docker build ,process paused,just as follows:
docker build -t registry.ap-southeast-1.aliyuncs.com/joyours_dev/cronjobonlinebackgroundtask:v1 -f Dockerfile.prod .
Sending build context to Docker daemon 25.14MB
Step 1/13 : FROM nginx
---> c316d5a335a5
Step 2/13 : COPY ./app /home/
---> Using cache
---> b3b5594156ff
Step 3/13 : WORKDIR /home
---> Using cache
---> e9fcfe5da215
Step 4/13 : ARG PROJECT_DIR=/var/petaplay/simplethai
---> Using cache
---> fa19c2174392
Step 5/13 : ARG MICROSERVICE_DIR=/var/petaplay/simplethai/microservice/
---> Using cache
---> c086111be060
Step 6/13 : ARG SERVICE_NAME=onlineservice
---> Using cache
---> e0e2035a756b
Step 7/13 : RUN mkdir -p $PROJECT_DIR/common/config
---> Running in 9b38ed579980
console stop at Step 7/13,

Docker container not showing site based on newly copied site configuration

This is my Dockerfile.
FROM ubuntu:devel
MAINTAINER ciasto
RUN apt-get update && apt-get install -y apache2 && apt-get clean && rm -rf /var/lib/apt/lists/\*
RUN mkdir /var/run/apache2
COPY mysite.conf /etc/apache2/sites-available/000-default.conf
ENV APACHE\_RUN\_USER www-data
ENV APACHE\_RUN\_GROUP www-data
ENV APACHE\_LOG\_DIR /var/log/apache2
ENV APACHE\_RUN\_DIR /var/run/apache2
EXPOSE 80
CMD \["/usr/sbin/apache2", "-D", "FOREGROUND"\]
I am trying to load my site instead of default 000-default.conf but even though the mysite.conf overwrites 000-default.conf I still keep getting the default homepage of Apache instead.
It doesn't have any affect of a2dissite and then running a2ensite:
# docker build -t myapache .
Sending build context to Docker daemon 3.072kB
Step 1/13 : FROM ubuntu:devel
---> 3dd27c0da934
Step 2/13 : MAINTAINER ciasto
---> Using cache
---> ca48c7010bf5
Step 3/13 : RUN apt-get update && apt-get install -y apache2 && apt-get clean && rm -rf /var/lib/apt/lists/*
---> Using cache
---> 3893438f7d96
Step 4/13 : RUN mkdir /var/run/apache2
---> Using cache
---> 6cc65fe8d352
Step 5/13 : COPY mysite.conf /etc/apache2/sites-available/000-default.conf
---> Using cache
---> 469c402f7c57
Step 6/13 : RUN a2dissite 000-default
---> Running in 2de611818fc0
Site 000-default disabled.
To activate the new configuration, you need to run:
service apache2 reload
Removing intermediate container 2de611818fc0
---> 64d8deed8833
Step 7/13 : RUN a2ensite 000-default
---> Running in cc8a0374ab0d
Enabling site 000-default.
To activate the new configuration, you need to run:
service apache2 reload
Removing intermediate container cc8a0374ab0d
---> 3af0de88b74b
Step 8/13 : ENV APACHE_RUN_USER www-data
---> Running in fa2146657f5f
Removing intermediate container fa2146657f5f
---> dac302f42282
Step 9/13 : ENV APACHE_RUN_GROUP www-data
---> Running in 7a3035b5866d
Removing intermediate container 7a3035b5866d
---> fdfc7a1d86e4
Step 10/13 : ENV APACHE_LOG_DIR /var/log/apache2
---> Running in 93cc22c81f55
Removing intermediate container 93cc22c81f55
---> d8e073243eed
Step 11/13 : ENV APACHE_RUN_DIR /var/run/apache2
---> Running in ca2b2829d60c
Removing intermediate container ca2b2829d60c
---> c7f535e2c031
Step 12/13 : EXPOSE 80
---> Running in 613564334e15
Removing intermediate container 613564334e15
---> adae0f0e2aed
Step 13/13 : CMD ["apachectl", "-D", "FOREGROUND"]
---> Running in 97c845feed9f
Removing intermediate container 97c845feed9f
---> 67f7823b995b
Successfully built 67f7823b995b
Successfully tagged myapache:latest
then I still get default page of Apache and checked by entering running container:
# apachectl -S
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
VirtualHost configuration:
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex default: dir="/var/run/apache2/" mechanism=default
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33
This should fix your problem here. To be add after the COPY:
RUN a2dissite 000-default
RUN a2ensite 000-default

Docker not running dist folder

I'm trying to make a container of my builded angular app.
I have already build my app. so inside actual folder I have
dist/ src/ and root files
Here's my docker folder
FROM node:alpine AS builder
WORKDIR /app
COPY . .
FROM nginx:alpine
COPY --from=builder /app/dist/* /usr/share/nginx/html/
built is ok
docker build -t ngapp:1.0.9 .
Step 1/5 : FROM node:alpine AS builder
---> 2d8f48ba52b1
Step 2/5 : WORKDIR /app
---> Using cache
---> d8d0d9d93f72
Step 3/5 : COPY . .
---> Using cache
---> 87c12f8c2ccf
Step 4/5 : FROM nginx:alpine
---> 36189e6707f4
Step 5/5 : COPY --from=builder /app/dist/* /usr/share/nginx/html/
---> Using cache
---> e39f00401242
Successfully built e39f00401242
I run my app
sudo docker run -p 8956:8080 ngapp:1.0.9
But when I go on the web page adresse the site is not running I get message : this site is not accessible
The nginx container doesn't listen on port 8080 (by default), so simply map to the valid port:
ports:
- 8956:80

Resources