I am new to networking but my target is to be able to ping a Docker container from the host and vice versa.
I know there are different types of networking in Docker (bridge,host,macvlan, [two types of ipvlan],none, overlay), however, I am not sure of the best approach for my situation. I think I wouldn’t need the host, bridge and none. Am I right?
to further elaborate on why I asked the question, I have a project that host communicates with hardware (Microcontrollers like Raspberry Pi, beaglebones, etc) and it uses IP addresses with ports (TCP and udp) to be able to transmit messages. I was thinking of using the Docker container as if these hardware were containers and thought of using 192.168. but set them on one separate network but have a route for the container to communicate with the host (192.168.3.110).
Use the default bridge driver unless you have a good reason not to. That is the easiest and you cans till make ports available by forwarding ports from the host to containers.
If you can’t ping containers, that means you either use Docker Desktop and containers are in a VM including their networks, or you are using MacVLAN as in your other topic
Well, I am using Linux containers in Linux OS VM as a host. In the Linux OS VM, I installed docker and docker-dekstop. I tried using the docker0 network where the containers have IP address 172.17.0.3 I tried to ping the host but couldn’t ping the container from the host or vice versa. I tried to look into the MacVLAN but I can’t seem to also ping each device in either way.
I tried to follow the steps from the docs and followed the steps in the video below,
Depending whether the application in the container:
requires clients to communicate with the application using a fixed port (only a problem if more than one container with the application should be running at the same time)
requires that multicast/broadcast traffic reaches the application
then macvlan on docker-ce is probably the way to go. If none of both things are required you can use either Docker Desktop or docker-ce with containers attached to bridge networks and published port to forward host ports to container ports.
Can you elaborate more on that? Does it mean that I wouldn’t need to install docker-desktop if I already have docker engine and rest? (from the installation steps)
I am creating a service that would be sending messages by knowing the IP address of the receiver and port. The receiver would be a containers.
Additional question:
What would happen if I converted the docker container to LXD?
Docker Desktop always uses a utility vm, regardless of the host OS, to provide the same experience across all platforms. I am not sure what the second sentence means. On Linux, you don’t have to use Docker Desktop, unless you need the extra functionality it provides, and can live with the restrictions it has with network or passing through devices. The differences have been discussed a lot in the forum, and I am sure the forum search will yield plenty of topics about it.
If your service can reach the target using the ip and port, then you can run multiple containers with the same application, and bind different host ports to reach different containers.
I just have a question. I managed to use the host IP to ssh into the container, my question is how can I make debian user to have same access level as root and access to the commands as I am trying to do ifconfig while I am in debian but keep on getting
debian@debian:~$ ifconfig
-bash: ifconfig: command not found
debian@debian:~$
Docker File:
# Use the official Debian base image
FROM debian:buster
# Install required packages
RUN apt-get update && apt-get install -y \
openssh-server \
sudo \
net-tools
# Create a new user 'debian' and set the password
RUN useradd -m -s /bin/bash debian
RUN echo 'debian:temppwd' | chpasswd
# Allow password authentication and root login via SSH
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config
# Remove existing SSH host keys and generate new ones
RUN rm -f /etc/ssh/ssh_host_*key && \
ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N '' && \
ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N '' && \
ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N '' && \
ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ''
# Add debian user to sudo group
RUN usermod -aG sudo debian
# Configure sudoers file to allow sudo without password prompt for users in the sudo group
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
# Ensure PATH includes directories for net-tools for debian user
RUN echo "export PATH=$PATH" >> /home/debian/.bashrc
CMD ["/bin/bash"]