LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Containers
User Name
Password
Linux - Containers This forum is for the discussion of all topics relating to Linux containers. Docker, LXC, LXD, runC, containerd, CoreOS, Kubernetes, Mesos, rkt, and all other Linux container platforms are welcome.

Notices


Reply
  Search this Thread
Old 04-20-2020, 09:58 AM   #1
drlolly
LQ Newbie
 
Registered: Apr 2020
Posts: 5

Rep: Reputation: Disabled
Question Why process in container not automatically connect to NIC?


In a process within a container you have to connect the IP stack to the outside world, using a veth connection. But you don’t have to do this with a normal process i.e. a process not running in a container but in the actual linux o.s. A normal process is automatically connected to the NIC. So how come a normal processes IP data structure allows access to the NIC but the IP data structure in the container is not, given that neither process ‘knows’ it is running in a container and both processes have the same set of data structures?
 
Old 04-21-2020, 01:19 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
I don't know what you mean by "automatically".

Processes connect to NICs if they are programmed or configured to do so. For example, the Apache web server uses the Listen directive in its configuration file to bind to a certain IP address. The process "sleep 1234 &" isn't connected to any NIC.

Can you provide an example of a process that automatically connects?
And of a process that doesn't when it runs in a container?
 
Old 04-21-2020, 03:16 AM   #3
drlolly
LQ Newbie
 
Registered: Apr 2020
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thanks for that, Berndbausch. Thinking about it more, I need to reframe the question. I think the question is really about the linux image used to run the container. So say if I write a c program that has a socket call with SOCK_DGRAM param and a call to the bind function. When I run this program on a linux o.s. the program can send UDP packets over the NIC. But if I run this program as a container, the program will not work unless the Linux image in the container has run the veth command. I basically understand what the veth command does. That is not the question. The question is the LINUX O.S. does not have to run the veth command in order for the program to work, but the linux image in the container does. Why is that? What bits of LINUX is the container image missing that prevents it from having access to the NIC?
 
Old 04-21-2020, 04:07 AM   #4
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
What kind of container is that? Linux Container, LXD, Docker, Virtuozzo, something else... ? If and how a container is connected to the network depends on its configuration.

I am not aware of a veth command.
 
Old 04-21-2020, 04:26 AM   #5
drlolly
LQ Newbie
 
Registered: Apr 2020
Posts: 5

Original Poster
Rep: Reputation: Disabled
The veth command is standard linux cf. http://man7.org/linux/man-pages/man4/veth.4.html
Re ‘what kind of container’. Linux container. There is an example of a container being built (using veth etc) in this talk by Jérôme Petazzoni,
https://www.youtube.com/watch?v=sK5i-N34im8
Note my question is not about veth. My question is what is missing in the linux image used in the container that means you have to use veth to allow your containerized process to connect to the NIC. The socket and bind functions will allows a c program to connect to the NIC when run as a linux process but not when run as process in a container.
 
Old 04-21-2020, 05:35 AM   #6
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
veth is not a command. It's a network interface. You need a veth device in the container's network namespace because the host's physical NICs are not in the container's network namespace.

Remember that the purpose of containers is shielding applications from each other. This separation of applications is accomplished with namespaces: Mount namespace, process namespace, network namespace, and a few others. To give processes in the container access to the network, there must be a connection from the container's network namespace to the physical network on the host. This is (often or always) done with veth pairs; one end of the veth pair is in the container's namespace, the other outside. The outside half of the veth pair could be plugged into a bridge. A physical network interface can then also be plugged into the same bridge.
 
Old 04-21-2020, 05:38 AM   #7
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by drlolly View Post
There is an example of a container being built (using veth etc) in this talk by Jérôme Petazzoni,
https://www.youtube.com/watch?v=sK5i-N34im8
Thanks for the link, but I don't have the time right now to watch a 50 minutes presentation. Besides, this is from a Docker meeting, not Linux Containers.
Quote:
Note my question is not about veth. My question is what is missing in the linux image used in the container
What's missing is the ability of the image to configure the host. The host must provide an environment that allows the container image to run. The veth pair is part of this environment.

EDIT: This is no different for a virtual machine, by the way. Except that processes in the virtual machine don't see the veth, since NICs are emulated. But veths are a common mechanism to connect VMs to the host's network.

Last edited by berndbausch; 04-21-2020 at 07:00 AM.
 
Old 04-21-2020, 06:57 AM   #8
dc.901
Senior Member
 
Registered: Aug 2018
Location: Atlanta, GA - USA
Distribution: CentOS/RHEL, openSuSE/SLES, Ubuntu
Posts: 1,005

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
@OP
Are you using one of the many Linux container images on docker hub (), or building your own?
Isn't the whole point of container is to keep it minimal and you have to define everything you want to do (dockerfile for example)?
 
Old 04-21-2020, 11:10 AM   #9
rigor
Member
 
Registered: Sep 2003
Location: 19th moon ................. ................Planet Covid ................Another Galaxy;............. ................Not Yours
Posts: 705

Rep: Reputation: Disabled
Quote:
Originally Posted by drlolly View Post
Thanks for that, Berndbausch. Thinking about it more, I need to reframe the question. I think the question is really about the linux image used to run the container. So say if I write a c program that has a socket call with SOCK_DGRAM param and a call to the bind function. When I run this program on a linux o.s. the program can send UDP packets over the NIC. But if I run this program as a container, the program will not work unless the Linux image in the container has run the veth command. I basically understand what the veth command does. That is not the question. The question is the LINUX O.S. does not have to run the veth command in order for the program to work, but the linux image in the container does. Why is that? What bits of LINUX is the container image missing that prevents it from having access to the NIC?
I might not be entirely clear on what you expect to happen, and I do apologize if I've misunderstood. Perhaps there's some issue with the context of the words, but you've mentioned DGRAM, yet you're using words such as "connect" and "connection". DGRAM, by definition, is a connection-LESS protocol. So I'm wondering, is there some expectation of connected-ness that isn't being met, because a DGRAM protocol is involved? Alternatively, I should point out that in one sense or another, a "Linux container" is a virtual environment. If I use a full blown "virtual machine" running on Linux, and if I wish what's inside the virtual machine, to interact with the physical World, then I have to make sure that something is set up to allow that. That might be something that's built in, in a way, to whatever "virtual machine" software I'm using, or it might be something for which I have to take action, to make sure it gets established. But one way or another, it is needed. E.G., I almost never use MS-Windows, but if I must, such as to be completely compatible with some file format which someone wishes used, and I need data from the outside world, over the physical NIC on the physical machine, then I have to make sure that the virtual machine can access the physical NIC.

Last edited by rigor; 04-21-2020 at 11:23 AM.
 
Old 04-22-2020, 12:08 PM   #10
drlolly
LQ Newbie
 
Registered: Apr 2020
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thanks Berndbaush,
I understand that one of the main functions that enables containers is namespaces. My point is that the Linux kernel image in the container is a sub-set of the functions supplied by Linux kernel. The Linux-host-kernel has a full set of Linux kernel functionality, including namespaces. So why is the Linux-host-kernel o.s able to connect to the NIC but the Linux-container-image-kernel is not?
The linux host is not providing an environment for the container. The container, including the linux-image, is just another linux process run by the linux host. The linux host does not provide anything to this process that it does not do to other processes.
You are correct in pointing out that veth is not a command. It is a virtual Ethernet device.
The presentation by Jerome is not about Docker containers. It is about what functionality has been added to the Linux kernel to allow containers. You might be particularly interested in the last 10 minutes of it, where he creates a container using the commands in the linux shell.
 
Old 04-22-2020, 08:00 PM   #11
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by drlolly View Post
Thanks Berndbaush,
I understand that one of the main functions that enables containers is namespaces. My point is that the Linux kernel image in the container is a sub-set of the functions supplied by Linux kernel.
This point is incorrect. There is no kernel image in the container. A container uses the host's kernel.

Virtual machines, on the other hand, run their own kernel, which is entirely separate from the host's kernel.
Quote:
The Linux-host-kernel has a full set of Linux kernel functionality, including namespaces. So why is the Linux-host-kernel o.s able to connect to the NIC but the Linux-container-image-kernel is not?
The processes in the container don't see the host's NICs because they have their own network namespace.

Quote:
The linux host is not providing an environment for the container.
I beg to differ.
Quote:
The container, including the linux-image, is just another linux process run by the linux host. The linux host does not provide anything to this process that it does not do to other processes.
Not quite. The processes in the container can't see the processes outside of the container. They can't see the filesystem outside of the container. And they can't see the NICs outside of the container.

Actually, this is precisely why containers exist: Processes in containers are not supposed to see all the host's resources. They are shielded from other containers, and they are shielded from the host.
Quote:
You are correct in pointing out that veth is not a command. It is a virtual Ethernet device.
The presentation by Jerome is not about Docker containers. It is about what functionality has been added to the Linux kernel to allow containers. You might be particularly interested in the last 10 minutes of it, where he creates a container using the commands in the linux shell.
OK, I did not check the presentation because I don't have the time. I have a rough idea about the features added to Linux, mostly CGroups and namespaces.

Last edited by berndbausch; 04-22-2020 at 08:01 PM.
 
Old 10-01-2020, 11:16 PM   #12
Michealfrins
LQ Newbie
 
Registered: Sep 2020
Posts: 5

Rep: Reputation: 0
Why process in container not automatically connect to NIC

Ubuntu Could not reliably determine the servers fully qualified domain name, using for ServerName , .

, , :


:
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Automatically configure copy of LXC container crts Slackware 2 12-09-2018 04:18 AM
linux container host os and container os question jzoudavy Linux - Newbie 1 09-01-2015 05:21 AM
LXer: Inside the Open Container Project: How Docker plans to unite the container market LXer Syndicated Linux News 0 06-23-2015 04:30 AM
if there are 2 NIC on the same machine, can a tcp client on one NIC connect to a tcp esolve Linux - Networking 3 05-20-2013 02:16 PM
Share glibc between Host process and a process within Linux Container alphy Linux - Virtualization and Cloud 0 02-16-2012 11:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Containers

All times are GMT -5. The time now is 10:14 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration