Reputation: 21
I am beginner in Docker and I created this Dockerfile
FROM nginx:1.13-alpine
ENV APP_PATH /app
ENV PATH $APP_PATH/node_modules/@angular/cli/bin/:$PATH
RUN apk add --update --no-cache nodejs && mkdir $APP_PATH && rm -rf /etc/nginx/conf.d/*
WORKDIR $APP_PATH
COPY . .
COPY nginx/default.conf /etc/nginx/conf.d/
RUN npm install \
&& ng build --aot --prod \
&& rm -rf /usr/share/nginx/html/* \
&& mv ./dist/* /usr/share/nginx/html/ \
&& npm cache clean \
&& apk del nodejs libstdc++ libgcc libuv http-parser ca-certificates \
&& rm -rf ./*
CMD ["nginx", "-g", "daemon off;"]
and Nginx config
server {
listen 80;
sendfile on;
default_type application/octet-stream;
gzip on;
gzip_http_version 1.1;
gzip_disable "MSIE [1-6]\.";
gzip_min_length 256;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_comp_level 9;
root /usr/share/nginx/html;
location / {
try_files $uri $uri/ /index.html =404;
}
}
I build image docker build --rm -t appName -f Dockerfile .
and run container docker run -it -p 8080:80 appName
Everything is ok. But I have one problem. I can't change my code interactively. I commit my changing docker commit ...
. I restart my container several times but nothing happened.
I would appreciate any advice.
Upvotes: 1
Views: 237
Reputation: 1333
Docker allows you to either copy files while building the image or you can mount local directory/files while running the container. Looking at your Dockerfile it looks like you are copying the code into the image while building, which is why the state in which your files are while building the image is what you will get when you run the container.
I am assuming you are using Linux/Mac, following is an example to mount your project directory inside docker container:
$ docker run -v "$PWD/dist:/usr/share/nginx/html" -it -p 8080:80 appName
Now any changes to files on the host OS will reflect in the docker container.
Note: your docker file is fine but you can make improvements by reading articles on the internet.
Upvotes: 1