Home > other >  Dockerize an angular Cli app but nothing append
Dockerize an angular Cli app but nothing append

Time:04-22

i try to dockerize my angular application so i made a Dockerfile :

FROM teracy/angular-cli as angular-built
WORKDIR /usr/src/app
COPY package.json package.json
RUN npm install
COPY . .
RUN ng build

FROM nginx:alpine
LABEL author="pleijan"
COPY --from=angular-built /usr/src/app/dist /usr/share/nginx/html

EXPOSE 4200

it build but when i run it on docker desktop here's what's going on :

/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2022/04/21 18:09:40 [notice] 1#1: using the "epoll" event method
2022/04/21 18:09:40 [notice] 1#1: nginx/1.21.6
2022/04/21 18:09:40 [notice] 1#1: built by gcc 10.3.1 20211027 (Alpine 10.3.1_git20211027) 
2022/04/21 18:09:40 [notice] 1#1: OS: Linux 5.10.102.1-microsoft-standard-WSL2
2022/04/21 18:09:40 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2022/04/21 18:09:40 [notice] 1#1: start worker processes
2022/04/21 18:09:40 [notice] 1#1: start worker process 33
2022/04/21 18:09:40 [notice] 1#1: start worker process 34
2022/04/21 18:09:40 [notice] 1#1: start worker process 35
2022/04/21 18:09:40 [notice] 1#1: start worker process 36

but after this nothing append, what i'm doing wrong ?

CodePudding user response:

The EXPOSE statement doesn't really do anything. It's mostly a bit of documentation on what port your container listens on. And in your case it's not correct, since Nginx listens on port 80 by default.

When you run the container, you should map port 80 to the port you want to use on the host. I.e.

docker run -d -p 4200:80 --rm <image name>

Now you should be able to reach your app at http://localhost:4200/

You should remove the EXPOSE statement in your Dockerfile, since it can confuse anyone looking at your Dockerfile later.

If you really want Nginx to listen on port 4200, you have to configure Nginx to do that, but IMO it's not worth it. Just have it listen on port 80.

  • Related