Vue CLI version is ~5.0.0. Vue version is 3.
This is my docker file
FROM node:lts-alpine
WORKDIR /app
COPY package*.json .
RUN ["npm", "install"]
COPY . .
EXPOSE 8080
CMD ["npm", "run", "serve"]
I build the image (image name is web) and run it with
docker run -p 8080:8080 --rm -it -v ${pwd}:/app -v /app/node_module web
If I make changes to source code I see no changes in browser. Inside container, if I inspect files, I can see that they have been changed, but I see no changes in browser.
I've seen examples of people running Vue container the following way:
docker run -p 8080:8080 -e CHOKIDAR_USEPOLLING=true -e HOST=0.0.0.0 --rm -it -v ${pwd}:/app -v /app/node_module web
However above doesn't really fix the problem.
I think it has something to do with web sockets but I'm kind of lost on what to try.
Related
Docker version 20.10.21
docker run command with -v option works as expected when the destination path is other than /app. But when the destination path is /app it doesn't work as expected.
command works as expected:
docker run -d -v ${pwd}:/app2 react-app
command not works as expected:
docker run -d -v ${pwd}:/app react-app
as seen in the snapshot there is not port for the second container
here is Dockerfile content
FROM node:14.16.0-alpine3.13
RUN addgroup app && adduser -S -G app app
USER app
WORKDIR /app
RUN mkdir data
COPY package*.json .
RUN npm install
COPY . .
ENV API_URL=http://api.myapp.com/
EXPOSE 3000
CMD [ "npm", "start" ]
You are running npm install in /app in the Dockerfile, but then at runtime you are mounting pwd over the files you installed in /app during the build process. Don't install your dependencies in /app during the build if you want to mount to /app at runtime.
Please try using $(pwd) instead of ${pwd}. Also if you are running it under Windows then you probably need to use some shell which implements pwd command correctly. E.g. Git Bash.
docker run -d -v $(pwd):/app react-app
Also once you start the container please check docker container inspect <container ID>, specifically Mounts section.
Or you can filter the output:
docker container inspect <container ID> -f '{{ .Mounts }}'
Also if you see that container exits immediately, please check its logs with
docker logs <container ID>
I solved it by excluding the node_modules from the mounting as:
docker run -d -v ${pwd}:/app -v /app/node_modules react-app
I have a docker file which when built and run stops. I am trying to run both client and server in one docker container. If there is any solution to use docker-compose, then that is already in place and working fine. Please advise how to keep the container up and running using docker run. Thanks!
Here is my docker file, package.json and screenshot of folder structure.
DockerFile contents:
FROM node:14.14.0-alpine
RUN apk update && apk add bash
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
WORKDIR /app
EXPOSE 3000
EXPOSE 4565
CMD ["npm","run","prebuild"]
docker build: command:
docker build -t sample .
docker run command:
docker run -d -it --name sm -v `pwd`:/app sample
Package.json:
I am creating an Astro js container with Docker on windows.
Dockerfile
FROM node:18-alpine3.15
RUN mkdir app
WORKDIR /app
COPY . .
RUN npm install
EXPOSE 24678
CMD ["npm","run","dev","--","--host"]
I build my image with the following command
docker build . -t astro
I run my container with this command
docker run --name astro1 -p 24678:24678 -v D:\Workspace\Docker\Practicas\docker-astro-example:/app -v /app/node_modules/ astro
So far without problems but when I make a change in the index.astro document it does not refresh the page to see the changes.
I am unable to run my docker image on Port 4000, even though I can run it on Port 80. What am I doing wrong here?
FROM node:latest as build
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM nginx:latest
COPY --from=build /usr/src/app/dist/admin /usr/share/nginx/html
EXPOSE 4200
I'm creating the image using the following command:
docker build --pull --rm -f "DockerFile" -t admin1:v1 "."
When I run it on port 80, I'm able to use it:
docker run --rm -d -p 4200:4200/tcp -p 80:80/tcp admin1:v1
However, when I run the following command, I'm unable to use it:
docker run --rm -d -p 4200:4200/tcp -p 4000:4000/tcp admin1:v1
I have researched similar questions online, but I haven't been able to fix the problem. Any suggestion will be greatly appreciated!
You need to map the docker container port to the docker host port.
Try the following Command
docker run --rm -d -p 4200:4200/tcp -p 4000:80/tcp admin1:v1
The following is the extract from the Docker Documentation
-p 8080:80 Map TCP port 80 in the container to port 8080 on the Docker host.
You can refer the link for further information.
Docker Documentation
I have the following dockerfile and everything works fine except for running the .exe
FROM golang:latest
# Set the Current Working Directory inside the container
WORKDIR $GOPATH/src/github.com/user/goserver
# Copy everything from the current directory to the PWD (Present Working Directory) inside the container
COPY . .
# Download all the dependencies
RUN go get -d -v ./...
# Install the package
RUN GOOS=linux GOARCH=amd64 go build -o goserver .
# This container exposes port 8080 to the outside world
EXPOSE 8080
# Run the executable
CMD ./goserver
The problem is that it does not execute './goserver'. I need to manually go into the container and then execute it. Any idea what could be going wrong here ?
The problem is the way you are running the container.
By running the container with the following:
docker run -it -p 8080:8080 goserver /bin/bash
you are overriding the command defined with CMD in Dockerfile to bin/bash command.
You can start the container in detached mode by running it as:
docker run -d -p 8080:8080 goserver
Further, if you want to later exec into the container then you can use the docker exec command.