Developing react app via docker container - reactjs

I am trying to develop a simple react app and I am trying to use docker for running a development server, but it is not connecting up in the browser
Here is the Dockerfile.dev
FROM node:alpine
WORKDIR /app
COPY package.json .
RUN npm install
COPY . .
CMD ["npm", "run", "start"]
EXPOSE 3000
Here are the two commands to create and run the container
docker build -f Dockerfile.dev .
docker run -p 3000:3000 <image_id>
It's starting a development server as the normal npm start does but it is not running in the browser at localhost:3000

You container will exist if you did not mention -it or -dit (if its not typo in question). The reason being stopped immediately because bash can't find any pseudo terminal to be allocated. You have to specify -it or -dit so that bash or sh can be allocated to a pseudo-terminal.
docker run --name test -p 3000:3000 <image_id>
If you run docker ps | grep test you will see in the output
"/bin/bash" {some} seconds ago Exited (0) {some} seconds ago
Now try to run with
docker run --name test -dit -p 3000:3000 <image_id>
or
docker run --name test -it -p 3000:3000 <image_id>
Good to go localhost:3000
Updated:
For window, docker toolbox follows these steps.
Click the appropriate machine (probably the one labeled "default")
Settings
Network > Adapter 1 > Advanced > Port Forwarding
Click "+" to add a
new Rule Set Host Port 3000 & Guest Port 3000; be sure to leave Host
IP and Guest IP empty
Run the command:
docker run -dit -p 3000:3000 ${image_id}
docker-toolbox-localhost

Related

Why docker with SQL Server disappeared?

I run SQL Server in container
docker run --network=bridge --name sql29 -h sql29 -it --rm -v h:/sql219data:/var/opt/mssql -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=sQL_19[pwd]" -p 12433:1433 -d mcr.microsoft.com/mssql/server:2019-latest
as described here:
https://learn.microsoft.com/en-us/sql/linux/tutorial-restore-backup-in-sql-server-container?view=sql-server-ver15
I see the active docker
docker ps
But if I try to create the new folder :
docker exec -it sql29 mkdir /var/opt/mssql/bkp22
then the docker disappeared.
docker ps
.........
How to understand: why the docker disappeared? Maybe the volume was mapped incorrectly?
As #Zeitounator commented, the tutorial you linked has a note saying that bind mounts don't work on Windows with the /var/opt/mssql directory:
Host volume mapping for Docker on Windows does not currently support mapping the complete /var/opt/mssql directory. However, you can map a subdirectory, such as /var/opt/mssql/data to your host machine.
You commented that your goal was to keep or restore databases between docker runs. You don't need a bind mount to do that, this is the primary purpose of a volume.
You can create a volume using docker volume create:
docker volume create sql219data
Then run your container using this volume:
docker run -v sql219data:/var/opt/mssql # ...
For debugging purposes you can remove the --rm option from your docker run command so the container won't be removed when stopped. You will then be able to read the logs of the container (even if it stopped):
docker logs sql29
# Then remove it to run the same `docker run` command again
docker rm sql29
docker run # ...

I have set up Docker volume but react app does not change on the fly

Hello i am making react app with Docker, i tried to make a volume to do not have to build docker every time but the app does not want to cooperate. Text does not change when I change him in IDE.
Docker command:
sudo docker run -p 3000:3000 -v /app/node_modules -v $(pwd):/app *image-id*
I guess you missed to assign a name for the volume. If you want to assign "name" as your volume name, you can try:
sudo docker run -p 3000:3000 -v name:/app/node_modules -v $(pwd):/app *image-id*

Why does docker run do nothing when i try to run my app?

I made a website to React and I'm trying to deploy it to an Nginx server by using Docker. My Dockerfile is in the root folder of my project and looks like this:
FROM tiangolo/node-frontend:10 as build-stage
WORKDIR /app
COPY . ./
RUN yarn run build
# Stage 1, based on Nginx, to have only the compiled app, ready for production with Nginx
FROM nginx:1.15
COPY --from=build-stage /app/build/ /usr/share/nginx/html
# Copy the default nginx.conf provided by tiangolo/node-frontend
COPY --from=build-stage /nginx.conf /etc/nginx/conf.d/default.conf
When I run docker build -t mywebsite . on the docker terminal I receive a small warning that I'm building a docker image from windows against a non-windows Docker host but that doesn't seem to be a problem.
However, when I run docker run mywebsite nothing happens, at all.
In case it's necessary, my project website is hosted on GitHub: https://github.com/rgomez96/Tecnolab
What are you expecting ? Nothing will happen on the console except the nginx log.
You should see something happening if you go to http:ip_of_your_container.
Otherwise, you can just launch your container with this command :
docker container run -d -p 80:80 mywebsite
With this command you'll be able to connect to your nginx at this address http://localhost as you are forwarding all traffic from the port 80 of your container to the port 80 of your host.

I created and run a sqlserver container, I stop it and I don't know how to run it again?

I created and run a SQL Server docker container. I stop it and I don't know how to start it again.
I use this command line:
sudo docker run --name sql_server_db -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=TEST_XXXXXXX' -p 1433:1433 -d mcr.microsoft.com/mssql/server:2017-latest
Type the following command to start the image, where <container_name> is the name of the image:
docker start <container_name>

ms sql server on mac os x with docker

I want to run sql-server on a mac os x computer. I have successfully build and start a docker container this way:
docker pull microsoft/mssql-server-linux
docker create -v /var/opt/mssql --name volume_mssql microsoft/mssql-server-linux /bin/true
docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=SuperPa3ss#1' -p 1433:1433 --volumes-from volume_mssql -d --name sqlserver1 microsoft/mssql-server-linux
It works fine. But i do not know what to do to restart this containers when the computer restarts...
Thanks
** edit **
if i type:
$ docker start volume_mssql
$ docker start sqlserver1
I have no error message, but i see the containers are "exited"
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f5721868bbe1 microsoft/mssql-server-linux "/bin/sh -c /opt/mss…" 15 hours ago Exited (255) 3 minutes ago sqlserver1
e5b88bb02a1b microsoft/mssql-server-linux "/bin/true" 15 hours ago Exited (0) 4 minutes ago volume_mssql
** edit **
$ docker container logs sqlserver1
Dump collecting thread [6] hit exception [6]. Exiting.
Dump collecting thread [7] hit exception [6]. Exiting.
For Autostart, docker container adds --restart always in docker run command.
Change your command to:
docker run -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=SuperPa3ss#1' --restart always -p 1433:1433 --volumes-from volume_mssql -d --name sqlserver1 microsoft/mssql-server-linux
Your container will start automatically when you restart the docker and PC.
From Terminal:
$ docker pull microsoft/mssql-server-linux
$ docker run -d — name sql_server_demo -e ‘ACCEPT_EULA=Y’ -e ‘SA_PASSWORD=Dev#998877’ -p 1433:1433 microsoft/mssql-server-linux
$ dokcer image ls
Now Download azure data studio from here,
https://learn.microsoft.com/en-us/sql/azure-data-studio/download-azure-data-studio?view=sql-server-ver15
Connect to SQL Server
Server: localhost
Authentication Type: SQL Login
User Name: sa
Password: Dev#99887
Steps by steps:
https://medium.com/macoclock/run-mssql-on-mac-using-docker-39460da701b9
You can find the container name by running: docker ps -a and use the name to start it using docker start <container-name>.
Alternatively, you can specify the container to start automatically by adding --restart always to the run command. This will make the container autostart once you restart the PC.

Resources