How to run an FTP server locally that a docker container can connect to - node.js

I'm currently running vsftpd locally on port 21 and have a node program that pulls data from it and that also works great.
I have containerised the deployment of the program on my local machine and it deploys fine but complains it can't connect to the FTP server on port 21 which I realised was because that port wasn't open.
Now if I open that port with something like -p 21:21 then this is blocking the FTP server which is bound to 21. I don't understand how I can run a test FTP server and this container at the same time?
Is it possible?

If the "containerised program" is only the node app, then if you connect to the ftp server via localhost:21 it will fail because inside that container there is no ftp server running on port 21. If you want to use the ftp server that runs on your host os, you need to run the container with --net="host", then the node app should connect to the ftp server with 127.0.0.1:21.
Another approach would be creating another container for the ftp server and using docker dns system to communicate the containers.

Related

How to display the webapp which is running in local host of a server in my laptop's browser

I have to say that, I am not a web developer and I don't know anything about how a web application works.
I've connected to a remote server via ssh, downloaded a project (Python, flask app) from github and run it there:
zwlayer#personalcomputer $ ssh myusername#ku.edu
myusername#ku.edu $ git clone https://github.com/.../project
myusername#ku.edu $ cd project
myusername#ku.edu $ env FLASK_APP=app.py FLASK_ENV=development env USE_CUDA=False flask run --host=0.0.0.0
Now, is it possible to get interact with that through my browser from my personalcomputer ?
You can use local port forwarding in SSH.
SSH to the server with command:
ssh -L 5000:127.0.0.1:5000 myusername#ku.edu
This will forward port 5000 on your host to port 5000 on the server
Run app with command:
flask run --host=127.0.0.1 --port=5000 (host and port options are used for the purpose of explicitness)
and you should be able to access the application by entering http://127.0.0.1:5000 in your browser.
Read more at https://www.booleanworld.com/guide-ssh-port-forwarding-tunnelling/
When starting a Flask development server using flask run, it starts listening on the loopback interface on port 5000 by default. By adding --host=0.0.0.0 you make the flask server listen on all network interfaces of the host. So, if you have full network access to the host, you should be able to point your browser to it. With the addresses given in your question, just enter http://ku.edu:5000 into the address bar of your browser to interact with your Flask web application.
However, this is not recommended, for security reasons! Since the server is listening on every network interfaces, any person with network access to the host computer can access the application. You're running the application with the Flask development server in development mode, which is not safe for production use.
Instead, I would suggest to use ssh port forwarding to access the flask development server, bound to the loopback interface of the remote host:
zwlayer#personalcomputer $ ssh -L 5000:localhost:5000 myusername#ku.edu
myusername#ku.edu $ git clone https://github.com/.../project
myusername#ku.edu $ cd project
myusername#ku.edu $ env FLASK_APP=app.py FLASK_ENV=development env USE_CUDA=False flask run
This way, ssh forwards all traffic directed to port 5000 of your local computer through the ssh tunnel to localhost:5000 at the remote host, i.e. to port 5000 of the remote host itself.
So, you can point your browser to http://localhost:5000, which is forwarded to the remote server's localhost:5000, which is where your flask server is listening. But—in contrast to the above solution—only local or ssh users at the remote host can access your application.

"The connection was reset" after starting my server [duplicate]

I'm running a webpack-dev-server application inside a Docker container (node:4.2.1). If I try to connect to the server port from within the container - it works fine. However, trying to connect it from the host computer results in reset connection (the port is published, of course). How can I fix it?
This issue is not a docker problem.
Add --host=0.0.0.0 to your webpack command.
You need to connect to your page like this:
http://host:port/webpack-dev-server/index.html
Look to the iframe mode
You need to make sure:
you docker container has mapped the EXPOSE'd port to a host port
docker run -p x:y
your VM (if you are using docker machine with a VM) has forwarded that mapped port to the actual host (the host of the VM).
See "How to access tomcat running in docker container from browser?"

Running NodeJs application on port 80 of amazon linux

I am trying to get a NodeJs application to run on a Amazon Linux server using port 80. Currently when I run the app it is defaulting to port 1024. I understand that this is due to the fact that I have to be root to run on port 80 but given I am on a aws linux box I am not able to run that as root. I have been digging for awhile but I am coming up short on what I need to adjust to get this to run properly.
sudo bash will allow you to connect as root on your EC2 Amazon Linux instance.
I would question why do you want to run NodeJS on port 80, the best practice would have a load balancer in front of your instance to accept HTTPS calls and relay to whatever port nodejs will run on your instance, in a private subnet.
I would suggest to read this doc to learn how to do this : https://aws.amazon.com/getting-started/projects/deploy-nodejs-web-app/

Remote debugging NodeJS Container on AWS

Running a NodeJS Docker Container on an EC2 instance, I'm trying to remote debug it, but keep getting "connection refused" from the instance.
What I've tried -
Opening ports in EC2 security groups
Exposing ports in Dockerfile, both the port the app is listening on and the debug port
Forwarding the port within the Docker run command using the -p flag
Making sure the app is accessible directly through the port it's configured to listen to
After trying all of these, the debug port is still inaccessible by the remote debugger or even telnet.
Any ideas what could cause this?

How should my local server communicate with an EC2 server?

I have a node.js server running on ec2. I'd like for that server to automatically push data to another node.js server that is running on my laptop.
What is the best way to do something like this?
You could use a service like showoff.io to create an entry point to access your local laptop, or you could just create an SSH tunnel by running this command on your laptop:
ssh -R port:localhost:remoteport ec2-host
That will allow port on the loopback interface of your EC2 server to connect to remoteport on your laptop.
Then just modify your code to connect to the node.js program running on your laptop via the IP of 127.0.0.1 and port of port.
You could have the EC2 node.js call a function from the local node.js, and pass the data as variables

Resources